#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
#define SCROLL_RIGHT_PIN 12
#define SCROLL_LEFT_PIN 13
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const unsigned char epd_bitmap_LogoBlock [] PROGMEM = {
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8
};
const unsigned char epd_bitmap_LeftArrow [] PROGMEM = {
0x0c, 0x14, 0x24, 0x44, 0x84, 0x84, 0x44, 0x24, 0x14, 0x0c
};
const unsigned char epd_bitmap_RightArrow [] PROGMEM = {
0xc0, 0xa0, 0x90, 0x88, 0x84, 0x84, 0x88, 0x90, 0xa0, 0xc0
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 448)
const unsigned char epd_bitmap_ScannerText [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe1, 0xc7, 0x8f, 0x0e, 0x26, 0x00,
0x00, 0x81, 0x12, 0x24, 0x48, 0x91, 0x28, 0x00, 0x00, 0x71, 0x00, 0x24, 0x48, 0x91, 0x30, 0x00,
0x00, 0x09, 0x01, 0xe4, 0x48, 0x9f, 0x20, 0x00, 0x00, 0x09, 0x02, 0x24, 0x48, 0x90, 0x20, 0x00,
0x00, 0x89, 0x12, 0x24, 0x48, 0x91, 0x20, 0x00, 0x00, 0x70, 0xe1, 0xe4, 0x48, 0x8e, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_OptionsText [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x22, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x78, 0xf1, 0x0e, 0x3c, 0x38, 0x00,
0x00, 0x22, 0x44, 0x41, 0x11, 0x22, 0x44, 0x00, 0x00, 0x22, 0x44, 0x41, 0x11, 0x22, 0x40, 0x00,
0x00, 0x22, 0x44, 0x41, 0x11, 0x22, 0x38, 0x00, 0x00, 0x22, 0x44, 0x41, 0x11, 0x22, 0x04, 0x00,
0x00, 0x22, 0x44, 0x41, 0x11, 0x22, 0x44, 0x00, 0x00, 0x1c, 0x78, 0x31, 0x0e, 0x22, 0x38, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_ScannerLogo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x7f,
0xfc, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x80, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x1f,
0xf8, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x3f,
0x80, 0x00, 0x7f, 0x00, 0x1f, 0x80, 0x00, 0x7f, 0xc0, 0x07, 0xe0, 0x00, 0x7f, 0xf0, 0x03, 0xe0,
0x00, 0x03, 0xfc, 0x01, 0xf0, 0x00, 0x00, 0xfe, 0x00, 0xf8, 0x00, 0x00, 0x7f, 0x80, 0x78, 0x00,
0x00, 0x1f, 0xc0, 0x3c, 0x00, 0x00, 0x07, 0xe0, 0x3c, 0x00, 0x78, 0x03, 0xe0, 0x1e, 0x00, 0x7f,
0x01, 0xf0, 0x1e, 0x00, 0x7f, 0xc0, 0xf8, 0x1e, 0x00, 0x1f, 0xe0, 0x78, 0x0f, 0x00, 0x03, 0xf0,
0x3c, 0x0f, 0x00, 0x00, 0xf8, 0x3c, 0x07, 0x00, 0x00, 0x78, 0x1e, 0x07, 0x80, 0x00, 0x3c, 0x1e,
0x07, 0xc0, 0x00, 0x3c, 0x1f, 0x03, 0xc0, 0x00, 0x1c, 0x0f, 0x03, 0xc0, 0x00, 0x1e, 0x0f, 0x01,
0xc0, 0x38, 0x1e, 0x07, 0x81, 0xe0, 0x7c, 0x0e, 0x07, 0x81, 0xe0, 0x7c, 0x0e, 0x03, 0x80, 0xe0,
0x7c, 0x0e, 0x03, 0x80, 0xe0, 0x38, 0x0e, 0x03, 0x80, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_OptionsLogo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x06,
0x03, 0xf0, 0x18, 0x00, 0x0f, 0x03, 0xf0, 0x3c, 0x00, 0x1f, 0x83, 0xf0, 0x7e, 0x00, 0x3f, 0xcf,
0xfc, 0xff, 0x00, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xfe, 0x00, 0x0f, 0xff, 0xff,
0xfc, 0x00, 0x07, 0xfe, 0x1f, 0xf8, 0x00, 0x03, 0xf8, 0x07, 0xf0, 0x00, 0x03, 0xf0, 0x03, 0xf0,
0x00, 0x07, 0xe0, 0x01, 0xf8, 0x00, 0x07, 0xc0, 0x00, 0xf8, 0x00, 0xff, 0xc0, 0x00, 0xff, 0xc0,
0xff, 0x80, 0x00, 0x7f, 0xc0, 0xff, 0x80, 0x00, 0x7f, 0xc0, 0xff, 0x80, 0x00, 0x7f, 0xc0, 0xff,
0x80, 0x00, 0x7f, 0xc0, 0x07, 0xc0, 0x00, 0xff, 0xc0, 0x07, 0xc0, 0x00, 0xf8, 0x00, 0x07, 0xe0,
0x01, 0xf8, 0x00, 0x03, 0xf0, 0x03, 0xf0, 0x00, 0x03, 0xf8, 0x07, 0xf0, 0x00, 0x07, 0xfe, 0x1f,
0xf8, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff,
0x00, 0x3f, 0xcf, 0xfc, 0xff, 0x00, 0x1f, 0x83, 0xf0, 0x7e, 0x00, 0x0f, 0x03, 0xf0, 0x3c, 0x00,
0x06, 0x03, 0xf0, 0x18, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00
};
const int amountOfOptions = 2;
const unsigned char* optionsTextArray[amountOfOptions] = {
epd_bitmap_ScannerText,
epd_bitmap_OptionsText
};
const unsigned char* optionsLogoArray[amountOfOptions] = {
epd_bitmap_ScannerLogo,
epd_bitmap_OptionsLogo
};
int optionIndex = 0;
void setup() {
Serial.begin(9600);
pinMode(SCROLL_RIGHT_PIN, INPUT);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
oled.setTextSize(1);
oled.setTextColor(BLACK);
setScreen();
}
void loop() {
int scrollRightPinValue = digitalRead(SCROLL_RIGHT_PIN);
int scrollLeftPinValue = digitalRead(SCROLL_LEFT_PIN);
if (scrollRightPinValue){
scrollRight();
delay(300);
}else if (scrollLeftPinValue){
scrollLeft();
delay(300);
}
}
void scrollRight(){
if (optionIndex < amountOfOptions - 1){
optionIndex = optionIndex + 1;
setScreen();
}
}
void scrollLeft(){
if (optionIndex > 0){
optionIndex = optionIndex - 1;
setScreen();
}
}
void setScreen(){
oled.clearDisplay();
drawScreenGUIElements();
drawPositionCursor();
drawOptionGUI();
oled.display();
}
void drawScreenGUIElements() {
oled.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, WHITE); // Fill the entire screen with white
if (!(optionIndex == 0)){
oled.drawBitmap(4, 28, epd_bitmap_LeftArrow, 6, 10, BLACK);
}
if (!(optionIndex == amountOfOptions - 1)){
oled.drawBitmap(119, 28, epd_bitmap_RightArrow, 6, 10, BLACK);
}
oled.drawBitmap(34, 5, epd_bitmap_LogoBlock, 62, 46, BLACK);
}
void drawPositionCursor(){
for (int i = amountOfOptions-1; i >= 0; i--){
oled.writePixel(125 - i*3, 4, BLACK);
if (amountOfOptions - 1 - i == optionIndex){
oled.writePixel(125 - i*3, 3, BLACK);
oled.writePixel(125 - i*3, 5, BLACK);
oled.writePixel(125 - i*3 + 1, 3, BLACK);
oled.writePixel(125 - i*3 + 1, 4, BLACK);
oled.writePixel(125 - i*3 + 1, 5, BLACK);
oled.writePixel(125 - i*3 - 1, 3, BLACK);
oled.writePixel(125 - i*3 - 1, 4, BLACK);
oled.writePixel(125 - i*3 - 1, 5, BLACK);
}
}
}
void drawOptionGUI(){
oled.drawBitmap(41, 53, optionsTextArray[optionIndex], 64, 12, BLACK);
oled.drawBitmap(47, 10, optionsLogoArray[optionIndex], 35, 35, BLACK);
}