#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define PIN_WS2812B 23 // The ESP32 pin GPIO16 connected to WS2812B
#define UP_BUTTON 16
#define DOWN_BUTTON 2
#define OKAY_BUTTON 4
#define NUM_PIXELS 32 // The number of LEDs (pixels) on WS2812B LED strip
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int currentStateUp = 0;
int currentStateDown = 0;
int currentStateOkay = 0;
int selection = 1;
void setup() {
pinMode(UP_BUTTON, INPUT_PULLDOWN);
pinMode(DOWN_BUTTON, INPUT);
pinMode(OKAY_BUTTON, INPUT);
ws2812b.begin(); // initialize WS2812B strip object (REQUIRED)
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
ws2812b.clear();
oled.clearDisplay();
}
void loop() {
currentStateUp = digitalRead(UP_BUTTON);
currentStateDown = digitalRead(DOWN_BUTTON);
currentStateOkay = digitalRead(OKAY_BUTTON);
if (currentStateUp == 1) {
ws2812b.clear();
oled.clearDisplay();
selection++;
delay(500);
}
if (currentStateDown == 1) {
ws2812b.clear();
oled.clearDisplay();
selection--;
delay(500);
}
if (currentStateOkay == 1) {
ws2812b.clear();
oled.clearDisplay();
delay(500);
}
Serial.println(selection);
//Serial.print("Up Button:");
//Serial.println(digitalRead(UP_BUTTON));
//Serial.print("Down Button:");
//Serial.println(digitalRead(DOWN_BUTTON));
selection = selection % 7;
if (selection <= 0) {
selection = 0;
oled.clearDisplay();
oled.display();
if (currentStateOkay == 1) {
ws2812b.clear();
ws2812b.show();
}
}
if (selection == 1) {
oled.fillRect(25, 12, 25, 40, WHITE);
oled.fillCircle(37, 12, 12, WHITE);
oled.fillCircle(37, 51, 12, WHITE);
oled.fillRect(79, 12, 25, 40, WHITE);
oled.fillCircle(91, 12, 12, WHITE);
oled.fillCircle(91, 51, 12, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 1; pixel <= 2; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 5; pixel <= 6; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 9; pixel <= 10; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 13; pixel <= 14; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 17; pixel <= 18; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 21; pixel <= 22; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 25; pixel <= 26; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 29; pixel <= 30; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
if (selection == 2) {
oled.fillRect(15, 12, 25, 40, WHITE);
oled.fillCircle(27, 12, 12, WHITE);
oled.fillCircle(27, 51, 12, WHITE);
oled.fillRect(69, 12, 25, 40, WHITE);
oled.fillCircle(81, 12, 12, WHITE);
oled.fillCircle(81, 51, 12, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 0; pixel <= 1; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 4; pixel <= 5; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 10; pixel <= 11; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 14; pixel <= 17; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 20; pixel <= 21; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 26; pixel <= 27; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 30; pixel <= 31; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
if (selection == 3) {
oled.fillRect(25, 12, 25, 40, WHITE);
oled.fillCircle(37, 12, 12, WHITE);
oled.fillCircle(37, 51, 12, WHITE);
oled.fillRect(79, 12, 25, 40, WHITE);
oled.fillCircle(91, 12, 12, WHITE);
oled.fillCircle(91, 51, 12, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 1; pixel <= 2; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 5; pixel <= 6; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 9; pixel <= 10; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 13; pixel <= 14; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 17; pixel <= 18; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 21; pixel <= 22; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 25; pixel <= 26; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 29; pixel <= 30; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
if (selection == 4) {
oled.fillRect(35, 12, 25, 40, WHITE);
oled.fillCircle(47, 12, 12, WHITE);
oled.fillCircle(47, 51, 12, WHITE);
oled.fillRect(89, 12, 25, 40, WHITE);
oled.fillCircle(101, 12, 12, WHITE);
oled.fillCircle(101, 51, 12, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 2; pixel <= 3; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 6; pixel <= 9; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 12; pixel <= 13; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 18; pixel <= 19; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 22; pixel <= 25; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 28; pixel <= 29; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
if (selection == 5) {
oled.fillRect(25, 12, 25, 40, WHITE);
oled.fillCircle(37, 12, 12, WHITE);
oled.fillCircle(37, 51, 12, WHITE);
oled.fillRect(79, 12, 25, 40, WHITE);
oled.fillCircle(91, 12, 12, WHITE);
oled.fillCircle(91, 51, 12, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 1; pixel <= 2; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 5; pixel <= 6; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 9; pixel <= 10; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 13; pixel <= 14; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 17; pixel <= 18; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 21; pixel <= 22; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 25; pixel <= 26; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 29; pixel <= 30; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
if (selection == 6) {
oled.drawLine(0, 0, 128, 64, WHITE);
oled.drawLine(1, 0, 128, 63, WHITE);
oled.drawLine(0, 1, 127, 64, WHITE);
oled.drawLine(0, 64, 128, 0, WHITE);
oled.drawLine(0, 63, 127, 0, WHITE);
oled.drawLine(1, 64, 128, 1, WHITE);
oled.display();
if (currentStateOkay == 1) {
for (int pixel = 0; pixel <= 1; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 6; pixel <= 7; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 10; pixel <= 13; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 18; pixel <= 21; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 24; pixel <= 25; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
for (int pixel = 30; pixel <= 31; pixel++) {
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0));
ws2812b.show();
}
}
}
}