/*
Project: SSD1306 OLED Display with Bitmap
Author: Thomas Edlinger for www.edistechlab.com
Date: Created 06.06.2020
Version: V1.0
- Used Aduino IDE V1.8.13
Required libraries (sketch -> include library -> manage libraries)
- Adafruit SSD1306 V2.2.1
- Adafruit GFX Library V1.8.3
Required Board (Tools -> Board -> Boards Manager...)
- Board: esp8266 by ESP8266 Community V2.7.4
- Board: ESP32 by Espressif Systems V1.0.2
Wirering for the Display:
SSD1306 ESP8266/MCU ESP32 Arduino UNO Arduino Mega
VCC 3.3V 3.3V 3.3V 3.3V
GND GND GND GND GND
SCL D1 / GPIO 5 GPIO 22 GPIO 9 GPIO 5
SDA D2 / GPIO 4 GPIO 21 GPIO 10 GPIO 53
*/
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#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, OLED_RESET);
int CLK = 13; // Pin 9 to clk on encoder
int DT = 12; // Pin 8 to DT on encoder
int RotPosition = 0;
int rotation;
int value;
boolean LeftRight;
void setup() {
pinMode (CLK,INPUT);
pinMode (DT,INPUT);
rotation = digitalRead(CLK);
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // I2C address = 0x3C
delay(1000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(15, 0);
display.print("Bandomat");
display.setCursor(30, 30);
display.print("V_0.01");
display.setTextSize(1);
display.setCursor(10, 55);
display.print("Powerd_by_DFStudio");
display.display();
delay (3000);
display.clearDisplay();
display.display();
}
void loop() {
value = digitalRead(CLK);
if (value != rotation){ // we use the DT pin to find out which way we turning.
if (digitalRead(DT) != value) { // Clockwise
RotPosition ++;
LeftRight = true;
} else { //Counterclockwise
LeftRight = false;
RotPosition--;
}
}
}