#include #include #include #include #include "config.h" #include "clockMsg.h" #include "master.h" #include "client.h" #if WITH_DISPLAY #include #include #define OLED_RESET /*4*/ Adafruit_SSD1306 display(OLED_RESET); #endif // Singleton instance of the radio driver RH_NRF24 nrf24(PIN_NRF24_CSN, PIN_NRF24_CE); // Address RH_BROADCAST_ADDRESS can be used for broadcasts as destination RHDatagram Datagram(nrf24, THIS_ADRESS); int masterConfigPin = PIN_MASTER_CLIENT_SELECT; static boolean isMaster = true; void setup() { Serial.begin(9600); while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only // what is our role? pinMode(masterConfigPin, INPUT); if (!digitalRead(masterConfigPin)) { isMaster = true; masterInit(); Serial.println("In Master-Mode"); } else { isMaster = false; clientInit(); Serial.println("In Client-Mode"); } if (!Datagram.init()) Serial.println("Init datagram with nrf24 failed"); #if WITH_DISPLAY display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.display(); delay(2000); // Clear the buffer. display.clearDisplay(); // draw a single pixel display.drawPixel(10, 10, WHITE); // Show the display buffer on the hardware. // NOTE: You _must_ call display after making any drawing commands // to make them visible on the display hardware! display.display(); delay(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Hello, world!"); #endif } void loop() { if (isMaster) { masterLoop(Datagram); } else { #if WITH_DISPLAY clientLoop(Datagram, display); #else clientLoop(Datagram); #endif } }