Completed next TODO: walkie talkie now can transmit data

This commit is contained in:
leca 2023-05-05 21:30:14 +03:00
parent c966199281
commit caab9a49f2
1 changed files with 36 additions and 14 deletions

View File

@ -1,4 +1,3 @@
//TODO: Learn how to use radio module, transmit data with it
//TODO: Learn how to use mic. in arduino, transmit plain sound among two arduinos and play it //TODO: Learn how to use mic. in arduino, transmit plain sound among two arduinos and play it
//TODO: Implement encryption and decryption using AES128, test it with text, then use to encrypt sound //TODO: Implement encryption and decryption using AES128, test it with text, then use to encrypt sound
@ -11,10 +10,12 @@
//Components //Components
LiquidCrystal_I2C lcd(0x27, 16, 2); LiquidCrystal_I2C lcd(0x27, 16, 2);
RF24 radio(7,8); RF24 radio(9,10);
//Settings //Settings
byte unsigned address = 1; //byte unsigned address = 1;
const byte address[6] = "00001";
unsigned short key = 0; unsigned short key = 0;
byte unsigned screen = 0; byte unsigned screen = 0;
const String seed = "1305b5cfa1a59e9789de"; // "random" seed ;) const String seed = "1305b5cfa1a59e9789de"; // "random" seed ;)
@ -49,8 +50,10 @@ void setup() {
//Setting up a radio module //Setting up a radio module
radio.begin(); radio.begin();
radio.setPALevel(RF24_PA_MIN); radio.setPALevel(RF24_PA_MIN);
radio.setChannel(0x00);
radio.setDataRate(RF24_250KBPS);
switchMode(); //default is recieving switchMode(); //default is recieving
// switchMode();
//Setting up a LCD //Setting up a LCD
lcd.init(); lcd.init();
lcd.backlight(); lcd.backlight();
@ -60,6 +63,18 @@ void setup() {
void loop() { void loop() {
// switchMode(); // switchMode();
if (!mode) {// transmit
const char text[] = "Hello world!";
radio.write(&text, sizeof(text));
} else { // receive
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
byte switchButtonValue = digitalRead(switchScreenButton); byte switchButtonValue = digitalRead(switchScreenButton);
byte increaseValue = digitalRead(increaseButton); byte increaseValue = digitalRead(increaseButton);
byte decreaseValue = digitalRead(decreaseButton); byte decreaseValue = digitalRead(decreaseButton);
@ -73,18 +88,22 @@ void loop() {
switch (screen) { switch (screen) {
case 0: case 0:
mode = !mode; mode = !mode;
Serial.println("xui");
break; break;
case 1: case 1:
if (decreaseValue == 0 && decreaseButtonLast == 1) if (decreaseValue == 0 && decreaseButtonLast == 1)
address = address > 0? address - 1 : 127; // address = address > 0? address - 1 : 127;
Serial.println("");
else else
address = address < 127? address + 1 : 0; // address = address < 127? address + 1 : 0;
Serial.println("");
break; break;
case 2: case 2:
if (decreaseValue == 0 && decreaseButtonLast == 1) if (decreaseValue == 0 && decreaseButtonLast == 1){
key --; key --;
else } else {
key ++; key ++;
}
break; break;
case 3: case 3:
encryption = !encryption; encryption = !encryption;
@ -95,14 +114,17 @@ void loop() {
switchScreenLast = switchButtonValue; switchScreenLast = switchButtonValue;
increaseButtonLast = increaseValue; increaseButtonLast = increaseValue;
decreaseButtonLast = decreaseValue; decreaseButtonLast = decreaseValue;
printOutput(); printOutput();
delay(100); // Serial.println(analogRead(A1));
analogWrite(6, 1);
delay(20);
} }
void switchMode () { void switchMode () {
if (mode) { // transmit -> recieve if (!mode) { // transmit -> recieve
radio.openReadingPipe(0, address); // radio.openReadingPipe(0, 0x0123456789LL);
radio.openReadingPipe(0, address);
radio.startListening(); radio.startListening();
} else { // recieve -> transmit } else { // recieve -> transmit
radio.openWritingPipe(address); radio.openWritingPipe(address);
@ -121,7 +143,7 @@ void printOutput () {
break; break;
case 1: case 1:
lcd.print("Addr.: "); lcd.print("Addr.: ");
lcd.print(address); // lcd.print(address);
break; break;
case 2: case 2:
lcd.print("Password: "); lcd.print("Password: ");