encrypted-walkie-talkie/code/code.ino

74 lines
1.7 KiB
Arduino
Raw Normal View History

2023-04-20 03:14:36 +03:00
//TODO: Divide interface with screens, each screen is a settings for each feature (address, mode, password, encryption on/off)
//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
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <AESLib.h>
//Components
LiquidCrystal_I2C lcd(0x27, 16, 2);
RF24 radio(7,8);
//Settings
byte unsigned address = -1;
unsigned short key = 0;
String seed = "1305b5cfa1a59e9789de"; // "random" seed ;)
String password;
bool mode = 0; // 0 = transmit, 1 = recieve, bool is 2 bytes less than byte :)
void switchMode();
void printOutput();
void updatePassword();
void setup() {
Serial.begin(9600);
//Setting up a radio module
radio.begin();
radio.setPALevel(RF24_PA_MIN);
switchMode(); //default is recieving
//Setting up a LCD
lcd.init();
lcd.backlight();
updatePassword();
}
void loop() {
switchMode();
printOutput();
delay(500);
}
void switchMode () {
if (mode) { // transmit -> recieve
radio.openReadingPipe(0, address);
radio.startListening();
} else { // recieve -> transmit
radio.openWritingPipe(address);
radio.stopListening();
}
mode = !mode;
}
void printOutput () {
lcd.setCursor(0, 0);
lcd.print("Mode: ");
lcd.print(mode? "rec." : "tra.");
lcd.setCursor(0, 1);
lcd.print("Addr.: ");
lcd.print(address);
// for (int i = 0; i < 5; i ++) lcd.print(address[i] - '0');
//lcd.print(mode);
}
void updatePassword() {
password = seed + key;
}