#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define btn1 15
#define btn2 14
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(100);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 2);
oled.println("Robotronix");
oled.display();
delay(500);
oled.clearDisplay();
oled.display();
}
void loop() {
oled.clearDisplay();
if (digitalRead(btn1) == LOW) {
delay(100);
oled.setTextSize(1);
oled.setTextColor(WHITE);
//VELOCIY cursor
oled.drawRect(0, 0, 128, 15, 1);
oled.setCursor(30, 4);
oled.print("VELOCITY:255");
//Balance cursor
oled.drawLine(40, 21, 0, 21, 1);
oled.drawLine(85, 21, 127, 21, 1);
oled.setCursor(43, 18);
oled.print("BALANCE");
//Left cursor
oled.drawRect(8, 28, 47, 14, 1);
oled.setCursor(17, 31);
oled.print("L:255");
//Right cursor
oled.drawRect(74, 28, 45, 14, 1);
oled.setCursor(82, 31);
oled.print("R:255");
//Test cursor
oled.drawRect(47, 46, 36, 15, 1);
oled.setCursor(54, 50);
oled.print("TEST");
oled.display();
}
if (digitalRead(btn2) == LOW) {
oled.clearDisplay();
oled.display();
}
}