diff --git a/code/code.ino b/code/code.ino index 06613af..2deff7b 100644 --- a/code/code.ino +++ b/code/code.ino @@ -10,7 +10,7 @@ //Components LiquidCrystal_I2C lcd(0x27, 16, 2); -RF24 radio(9,10); +RF24 radio(9,10); // CE, CSN //Settings //byte unsigned address = 1; @@ -22,6 +22,9 @@ const String seed = "1305b5cfa1a59e9789de"; // "random" seed ;) String password; bool mode = 0; // 0 = transmit, 1 = recieve, bool is 2 bytes less than byte :) bool encryption = 1; // will the trafic be encrypted? +byte value = 0; + +bool isScreenChanged = true; // we must display first time //Switch screen button const byte switchScreenButton = 2; @@ -49,11 +52,11 @@ void setup() { //Setting up a radio module radio.begin(); - radio.setPALevel(RF24_PA_MIN); + radio.setPALevel(RF24_PA_MAX); radio.setChannel(0x00); radio.setDataRate(RF24_250KBPS); switchMode(); //default is recieving -// switchMode(); + switchMode(); //Setting up a LCD lcd.init(); lcd.backlight(); @@ -66,7 +69,8 @@ void loop() { if (!mode) {// transmit const char text[] = "Hello world!"; - radio.write(&text, sizeof(text)); + if (radio.write(&text, sizeof(text))) Serial.println("данные успешно отправлены"); + else Serial.println("хуй там"); } else { // receive if (radio.available()) { char text[32] = ""; @@ -81,10 +85,12 @@ void loop() { if (switchButtonValue == 0 && switchScreenLast == 1) { - screen = screen < 3? screen + 1 : 0; + screen = screen < 3? screen + 1 : 0; + isScreenChanged = true; } if ((decreaseValue == 0 && decreaseButtonLast == 1) || increaseValue == 0 && increaseButtonLast == 1) { + isScreenChanged = true; switch (screen) { case 0: mode = !mode; @@ -114,11 +120,12 @@ void loop() { switchScreenLast = switchButtonValue; increaseButtonLast = increaseValue; decreaseButtonLast = decreaseValue; - printOutput(); + if (isScreenChanged) + printOutput(); // Serial.println(analogRead(A1)); - analogWrite(6, 1); - - delay(20); + analogWrite(6, value); + value +=5; + delay(50); } void switchMode () { @@ -153,7 +160,8 @@ void printOutput () { lcd.print("Enc.: "); lcd.print(encryption? "yes" : "no"); } - + + isScreenChanged = false; // for (int i = 0; i < 5; i ++) lcd.print(address[i] - '0'); //lcd.print(mode);