Hello all! I have been working on a project for a while. My goal is to make a super smart switch using Blynk. I have the switch part of it (that was the easy part), but the next step is to add a display. I am using a WEMOS D1 mini lite, a relay shield, and an OLED shield.
Here is the relay shield
Here is the OLED display
What I want is for the OLED screen to display “ON” when the relay is switched on and for it to display “OFF” when the display is switched off. I have gotten the OLED to display "ON or “OFF” simply by typing “ON” or “OFF” into display.println().
I have no idea how to do this and I would really appreciate some help.
Also, I would be controlling this from the Blynk app
Here is the code I’m using
Relay:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "################################";
char ssid[] = "#############";
char pass[] = "########";
void setup()
{Preformatted text
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
OLED:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(45, 10);
display.println("On");
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
}
I have only gotten as far as this in combining the control of the relay and the display together:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
#define BLYNK_PRINT Serial
void setup() {
char auth[] = "###############";
char ssid[] = "#############";
char pass[] = "############";
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(45, 10);
display.println("ON");
display.display();
delay(2000);
display.clearDisplay();
}
void loop()
{
Blynk.run();
}
Unfortunately, what is displayed is only affected by what I tell it to display in the code, not the state of the relay.
What I need to know is how to write the code that will update the display based on the state of the relay.