#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
map<string, list> ColorsAndTheirValues{
"red" : [ 255, 0, 0 ],
"green" : [ 0, 255, 0 ],
"blue" : [ 0, 0, 255 ],
"purple" : [ 255, 0, 255 ],
"orange" : [ 255, 125, 0 ],
"yellow" : [ 255, 255, 0 ],
}
map<string, list> StatOfLed{
"Wrong" : [ 0, 0, 0 ],
"RightWrongPlace" : [ 125, 0, 0 ],
"right" : [ 255, 0, 0 ],
}
map<string, int> buttons{
"red" : 20,
"yellow" : 21,
"blue" : 22,
"green" : 23,
"white" : 24,
"gray" : 25
}
map<string, list> ledAndTheirPins {
"led1" : [ 23, 22, 21 ]
}
void SetColorInLed(list list_pins, list list_colors) {
analogWrite(list_pins, list_colors), // red pin [0]
analogWrite(list_pins, list_colors), // green pin[1]
analogWrite(list_pins, list_colors) // blue pin[2]
}
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear();
Serial.begin(115200);
Serial.println("Hello, ESP32!");
for
i = 0, i < 20, i++ { // initialize pins
pinMode(i, OUTPUT);
}
for
i = 20, i < 30, i++ { // initialize buttons
pinMode(i, INPUT_PULLUP);
}
}
void loop() {
// make a random generator from the ColorsAndTheirValues loop it 4 time to get 4 different colors, store them in a list
for (int i = 0; i < 4; i++) {
random_colors.push_back(ColorsAndTheirValues[random(0, ColorsAndTheirValues.size())]);
}
// read buttons and ligth up leds accordingly
if (button1 == HIGH) {
SetColorInLed(list_pins["led1"], list_colors["red"]);
}
//calculate the guess and show it on the lcd
list<string> guess;
for (int i = 0; i < 4; i++) {
guess.push_back(ColorsAndTheirValues[random(0, ColorsAndTheirValues.size())]);
}
lcd.setCursor(0, 0);
lcd.print("Guess: ");
for (auto color : guess) {
lcd.print(color + " ");
}
// reset leds
//continue the game until the user wins or the points are over
//reset everything for the next game: set random list to empty, clear lcd, turn off leds
delay(10); // this speeds up the simulation
}