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