#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int relay1= 27;
const int buttonPin1 = 18;
const int buttonPin2 = 2;
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {
Serial.begin(115200);
delay(1000);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
pinMode(relay1, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
display.clearDisplay();
if (buttonState1 == HIGH) {
digitalWrite(relay1, HIGH);
display.setTextSize(1);
display.setCursor(0,0);
display.print("Relay 1 On");
display.display();
}
if (buttonState2 == HIGH) {
digitalWrite(relay1, LOW);
display.setTextSize(1);
display.setCursor(0,27);
display.print("Relay 1 Off");
display.display();
}
}
Loading
ssd1306
ssd1306