Screen now prints only when changed
This commit is contained in:
parent
5a5cd747a0
commit
7d468842ae
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
//Components
|
//Components
|
||||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||||
RF24 radio(9,10);
|
RF24 radio(9,10); // CE, CSN
|
||||||
|
|
||||||
//Settings
|
//Settings
|
||||||
//byte unsigned address = 1;
|
//byte unsigned address = 1;
|
||||||
|
@ -22,6 +22,9 @@ const String seed = "1305b5cfa1a59e9789de"; // "random" seed ;)
|
||||||
String password;
|
String password;
|
||||||
bool mode = 0; // 0 = transmit, 1 = recieve, bool is 2 bytes less than byte :)
|
bool mode = 0; // 0 = transmit, 1 = recieve, bool is 2 bytes less than byte :)
|
||||||
bool encryption = 1; // will the trafic be encrypted?
|
bool encryption = 1; // will the trafic be encrypted?
|
||||||
|
byte value = 0;
|
||||||
|
|
||||||
|
bool isScreenChanged = true; // we must display first time
|
||||||
|
|
||||||
//Switch screen button
|
//Switch screen button
|
||||||
const byte switchScreenButton = 2;
|
const byte switchScreenButton = 2;
|
||||||
|
@ -49,11 +52,11 @@ void setup() {
|
||||||
|
|
||||||
//Setting up a radio module
|
//Setting up a radio module
|
||||||
radio.begin();
|
radio.begin();
|
||||||
radio.setPALevel(RF24_PA_MIN);
|
radio.setPALevel(RF24_PA_MAX);
|
||||||
radio.setChannel(0x00);
|
radio.setChannel(0x00);
|
||||||
radio.setDataRate(RF24_250KBPS);
|
radio.setDataRate(RF24_250KBPS);
|
||||||
switchMode(); //default is recieving
|
switchMode(); //default is recieving
|
||||||
// switchMode();
|
switchMode();
|
||||||
//Setting up a LCD
|
//Setting up a LCD
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
|
@ -66,7 +69,8 @@ void loop() {
|
||||||
|
|
||||||
if (!mode) {// transmit
|
if (!mode) {// transmit
|
||||||
const char text[] = "Hello world!";
|
const char text[] = "Hello world!";
|
||||||
radio.write(&text, sizeof(text));
|
if (radio.write(&text, sizeof(text))) Serial.println("данные успешно отправлены");
|
||||||
|
else Serial.println("хуй там");
|
||||||
} else { // receive
|
} else { // receive
|
||||||
if (radio.available()) {
|
if (radio.available()) {
|
||||||
char text[32] = "";
|
char text[32] = "";
|
||||||
|
@ -82,9 +86,11 @@ void loop() {
|
||||||
|
|
||||||
if (switchButtonValue == 0 && switchScreenLast == 1) {
|
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) {
|
if ((decreaseValue == 0 && decreaseButtonLast == 1) || increaseValue == 0 && increaseButtonLast == 1) {
|
||||||
|
isScreenChanged = true;
|
||||||
switch (screen) {
|
switch (screen) {
|
||||||
case 0:
|
case 0:
|
||||||
mode = !mode;
|
mode = !mode;
|
||||||
|
@ -114,11 +120,12 @@ void loop() {
|
||||||
switchScreenLast = switchButtonValue;
|
switchScreenLast = switchButtonValue;
|
||||||
increaseButtonLast = increaseValue;
|
increaseButtonLast = increaseValue;
|
||||||
decreaseButtonLast = decreaseValue;
|
decreaseButtonLast = decreaseValue;
|
||||||
printOutput();
|
if (isScreenChanged)
|
||||||
|
printOutput();
|
||||||
// Serial.println(analogRead(A1));
|
// Serial.println(analogRead(A1));
|
||||||
analogWrite(6, 1);
|
analogWrite(6, value);
|
||||||
|
value +=5;
|
||||||
delay(20);
|
delay(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchMode () {
|
void switchMode () {
|
||||||
|
@ -154,6 +161,7 @@ void printOutput () {
|
||||||
lcd.print(encryption? "yes" : "no");
|
lcd.print(encryption? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isScreenChanged = false;
|
||||||
|
|
||||||
// for (int i = 0; i < 5; i ++) lcd.print(address[i] - '0');
|
// for (int i = 0; i < 5; i ++) lcd.print(address[i] - '0');
|
||||||
//lcd.print(mode);
|
//lcd.print(mode);
|
||||||
|
|
Loading…
Reference in New Issue