#include <Wire.h>
#include <vector>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <string>
#define ScreenWidth 128
#define ScreenHeight 64
Adafruit_SSD1306 Display(ScreenWidth, ScreenHeight, &Wire, -1);
const int RedLed = 8;
const int YellowLed = 6;
const int GreenLed = 4;
const int BlueLed = 19;
const int RedButton = 9;
const int YellowButton = 7;
const int GreenButton = 5;
const int BlueButton = 18;
const int MyScl = 2;
const int MySda = 3;
std::vector<int> Order;
int RoundNumber = 1;
//[AnyPressed, RedPressed, YellowPressed, GreenPressed, BluePressed]
std::vector<bool> GetAllPushedButtons() {
std::vector<bool> Pushed;
bool RedPressed = digitalRead(RedButton) == LOW;
bool YellowPressed = digitalRead(YellowButton) == LOW;
bool GreenPressed = digitalRead(GreenButton) == LOW;
bool BluePressed = digitalRead(BlueButton) == LOW;
Pushed.push_back(RedPressed || YellowPressed || GreenPressed || BluePressed); // any
Pushed.push_back(RedPressed);
Pushed.push_back(YellowPressed);
Pushed.push_back(GreenPressed);
Pushed.push_back(BluePressed);
return Pushed;
}
void setup() {
Serial.begin(115200);
Wire.begin(MySda, MyScl);
// LED
pinMode(RedLed, OUTPUT);
pinMode(YellowLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(BlueLed, OUTPUT);
// Buttons
pinMode(RedButton, INPUT_PULLUP);
pinMode(YellowButton, INPUT_PULLUP);
pinMode(GreenButton, INPUT_PULLUP);
pinMode(BlueButton, INPUT_PULLUP);
digitalWrite(RedLed, LOW);
digitalWrite(YellowLed, LOW);
digitalWrite(GreenLed, LOW);
digitalWrite(BlueLed, LOW);
Display.setRotation(2);
if (!Display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED NOT FOUND!");
for (;;);
}
}
void CreateOLEDRoundScreen() {
Display.clearDisplay();
Display.setCursor(0, 0);
std::string Text = "Round: " + std::to_string(RoundNumber);
Display.print(Text.c_str());
Display.display();
}
void AddA() {}
void ShowWhatToCopy() {
for (int Value : Order) {
if (Value == 0) {
} else if (Value == 1) {
} else if (Value == 2) {
} else if (Value == 3) {
}
}
}
void loop() {
auto Buttons = GetAllPushedButtons();
Serial.print("[ ");
for (bool B : Buttons) {
Serial.print(B);
Serial.print(" ");
}
Serial.println("]");
Display.clearDisplay();
Display.setTextSize(1);
Display.setTextColor(SSD1306_WHITE);
Display.setCursor(0, 0);
Display.print("Hello! Click any");
Display.setCursor(0, 10);
Display.print("button to play!");
Display.display();
if (Buttons[0]) {
CreateOLEDRoundScreen();
while (true) {
}
}
delay(10);
}