diff --git a/code/code.ino b/code/code.ino index 0c71ea1..06613af 100644 --- a/code/code.ino +++ b/code/code.ino @@ -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,17 +50,31 @@ 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(); - + updatePassword(); } 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: ");