#include SoftwareSerial mySerial(D9, D8); // RX, TX #define BUTTON1PIN D2 #define BUTTON2PIN D3 const uint8_t my_address = 0; // My network address const uint8_t recipient_address = 1; // Default peripheral address const char message_ending = '\n'; const uint8_t animation_max = 5; bool light_on = false; uint8_t animation_state = 0; void setup() { pinMode(BUTTON1PIN, INPUT_PULLUP); pinMode(BUTTON2PIN, INPUT_PULLUP); mySerial.begin(9600); //Serial.begin(9600); } // Message format: // "Node 1, this is your Node 0 speaking, light on." void loop() { if (!digitalRead(BUTTON1PIN)) { if (light_on){ mySerial.write(recipient_address); mySerial.write(my_address); mySerial.write('f'); // Command light off mySerial.write(message_ending); light_on = false; } else { mySerial.write(recipient_address); mySerial.write(my_address); mySerial.write('o'); // Command light on mySerial.write(message_ending); light_on = true; } delay(50); while(!digitalRead(BUTTON1PIN)); // Wait until button released } if (!digitalRead(BUTTON2PIN)) { if (animation_state == animation_max){ animation_state = 0; } else { animation_state += 1; } mySerial.write(recipient_address); mySerial.write(my_address); mySerial.write(animation_state); // Command light state mySerial.write(message_ending); delay(50); while(!digitalRead(BUTTON2PIN)); // Wait until button released } // For debugging: //if (mySerial.available()) { // Serial.write(mySerial.read()); //} }