#include #include #include #include #include #define SS 3 //=D3 #define BTN_LEFT 1 // button left pin #define BTN_RIGHT 2 // button right pin #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int buttonStateLeft = 0; // variable for reading the pushbutton status int buttonStateRight = 0; // variable for reading the pushbutton status unsigned long previousMillis = 0; // will store last time LED was updated const long interval = 3000; // interval at which to blink/switch words (milliseconds) bool msgSent = false; // store state about the message #define CURSORS_X 30 #define CURSORS_Y 10 void setup() { Serial.begin(9600); delay(4000); Serial.println("Wally !!"); LoRa.setPins(SS); while (!LoRa.begin(868E6)) { Serial.println("Starting LoRa failed!"); delay (1000); } // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); } display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(CURSORS_X, CURSORS_Y); // Start at top-left corner display.display(); delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); pinMode(BTN_LEFT, INPUT); pinMode(BTN_RIGHT, INPUT); } void loop() { // read the state of the pushbutton value: buttonStateLeft = digitalRead(BTN_LEFT); buttonStateRight = digitalRead(BTN_RIGHT); // check if any of the pushbuttons are pressed. If it is, the buttonState is HIGH: if ((buttonStateLeft == HIGH) && (!msgSent)) { // send packet "bike" to the network. LoRa.beginPacket(); LoRa.print("bike"); LoRa.endPacket(); display.clearDisplay(); display.setCursor(CURSORS_X, CURSORS_Y); display.print(F("SIGNAL")); display.setCursor(CURSORS_X+15, CURSORS_Y+30); display.print(F("SENT")); display.display(); msgSent = true; previousMillis = millis(); buttonStateLeft = LOW; buttonStateRight = LOW; } if (buttonStateRight == HIGH && (!msgSent)) { // send packet "merci" to the network. LoRa.beginPacket(); LoRa.print("merci"); LoRa.endPacket(); } if(msgSent) { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { display.clearDisplay(); display.display(); msgSent = false; } } }