From 7022455ed7bec84a7217fd906e0d8e53a0c4c2fb Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 3 Jul 2023 16:13:26 +0300 Subject: [PATCH] a lot of changes --- code/code.ino | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/code/code.ino b/code/code.ino index 2deff7b..411d22e 100644 --- a/code/code.ino +++ b/code/code.ino @@ -11,6 +11,8 @@ //Components LiquidCrystal_I2C lcd(0x27, 16, 2); RF24 radio(9,10); // CE, CSN +const byte micPin = A0; + //Settings //byte unsigned address = 1; @@ -27,24 +29,29 @@ byte value = 0; bool isScreenChanged = true; // we must display first time //Switch screen button -const byte switchScreenButton = 2; +const byte switchScreenButton = A1; byte switchScreenLast; //IncreaseButton -const byte increaseButton = 3; +const byte increaseButton = A2; byte increaseButtonLast; //DecreaseButton -const byte decreaseButton = 4; +const byte decreaseButton = A3; byte decreaseButtonLast; void switchMode(); void printOutput(); void updatePassword(); +//short micValue = 337; +//const short micBaseline = 337;// 3.3v / 2 = 1.56v, 1.56/5*1024 = 337. + +short micValues[32]; + void setup() { Serial.begin(9600); - + pinMode(micPin, INPUT); //Setting up buttons pinMode(switchScreenButton, INPUT_PULLUP); pinMode(increaseButton, INPUT_PULLUP); @@ -65,18 +72,19 @@ void setup() { } void loop() { -// switchMode(); - + switchMode(); if (!mode) {// transmit - const char text[] = "Hello world!"; - if (radio.write(&text, sizeof(text))) Serial.println("данные успешно отправлены"); - else Serial.println("хуй там"); + for (int i = 0; i < 32; i ++) { + micValues[i] = analogRead(micPin) << 2; + } + radio.write(micValues, 32); } else { // receive if (radio.available()) { - char text[32] = ""; - radio.read(&text, sizeof(text)); - Serial.println(text); - } + radio.read(micValues, 32); + for (int i = 0; i < 32; i++) { + PORTD = micValues[i]; + } + } } byte switchButtonValue = digitalRead(switchScreenButton); @@ -94,15 +102,14 @@ 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; - Serial.println(""); + 1+1; else // address = address < 127? address + 1 : 0; - Serial.println(""); + 1+1; break; case 2: if (decreaseValue == 0 && decreaseButtonLast == 1){ @@ -122,10 +129,6 @@ void loop() { decreaseButtonLast = decreaseValue; if (isScreenChanged) printOutput(); -// Serial.println(analogRead(A1)); - analogWrite(6, value); - value +=5; - delay(50); } void switchMode () { @@ -146,10 +149,10 @@ void printOutput () { switch (screen) { case 0: lcd.print("Mode: "); - lcd.print(mode? "rec." : "tra."); + lcd.print(mode? "receive" : "transmit"); break; case 1: - lcd.print("Addr.: "); + lcd.print("Address: "); // lcd.print(address); break; case 2: @@ -157,7 +160,7 @@ void printOutput () { lcd.print(key); break; case 3: - lcd.print("Enc.: "); + lcd.print("Encryption: "); lcd.print(encryption? "yes" : "no"); }