Items Needed:
Arduino UNO
BreadBord
Jumper Wires Male to Male
Jumper Wires Kit
12V 1A Power Adaptor
Push Buttons 100 mm (10 cm diameter)
Push Button 60 mm (6 cm diameter)
Battery Coss Connector (DJ621)
NPN Transistor PN2222 (2N2222)
Resistor 4.7 KOhm 0.5 Watt
LCD 2 Lines I2C
Jumper Wires Male to Female
Video:
Code:
//Simon says in LEDS. The game here ra7 betdawe leds w ba3den l player bado y3idoun. int buttonPins [] ={2,3,4,5,6}; int ledPins [] = {7,8,9,10,11}; int numberButtons = 5; int roundCounter = 0; int roundLedCounter = 3; unsigned long roundDuration = 10000; // 10 seconds la kel round int BoardLEDS [50]; int userBoardLEDS[50]; int resetButtonPin = 13; int resetLedPin = 12; bool start = false; //LCD stuff #include "LCD.h" #include <LiquidCrystal_I2C.h> #define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); void setup() { // put your setup code here, to run once: Serial.begin(9600); lcd.begin(20,4); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.setCursor(0,0); lcd.setCursor(0,0); lcd.print("C.B.ELECTRONICS"); delay(500); lcd.setCursor(0,1); lcd.print("Lebanese Park"); delay(500); lcd.clear(); lcd.setCursor(0,0); lcd.print("Press"); lcd.setCursor(0,1); lcd.print("reset button"); randomSeed(analogRead(0)); for(int i=0;i<5;i++) { pinMode(buttonPins[i], INPUT_PULLUP); pinMode(ledPins[i], OUTPUT); } pinMode(resetButtonPin, INPUT_PULLUP); pinMode(resetLedPin, OUTPUT); TurnONLEDS(); ResetFunc(); TurnOFFLEDS(); lcd.clear(); } void loop() { // put your main code here, to run repeatedly: PlayRound(); } void PlayRound() { delay(1000); lcd.setCursor(0,0); lcd.print("Round: "); lcd.print(roundCounter+1); for (int i=0;i<roundLedCounter;i++) { BoardLEDS[i]=random(7,12); } for (int i=0;i<roundLedCounter;i++) { digitalWrite(BoardLEDS[i], HIGH); delay(3000); digitalWrite(BoardLEDS[i], LOW); delay(300); } lcd.clear(); lcd.setCursor(0,0); lcd.print("Balachna 1s"); delay(1000); unsigned long startTime = millis(); int counter = 0; while( (millis() - startTime) < roundDuration) { lcd.setCursor(0,1); lcd.print((roundDuration - (millis() - startTime)) / 1000); for(int i=0;i<numberButtons;i++) { if(digitalRead(buttonPins[i])==LOW) { Serial.println(i); Serial.println("Hayda l butoon makbous"); userBoardLEDS[counter]=ledPins[i]; digitalWrite(ledPins[i], HIGH); delay(500); digitalWrite(ledPins[i], LOW); delay(100); counter ++; while(digitalRead(buttonPins[i])==LOW) { //do nothing } } } bool win = true; if (counter == roundLedCounter) { for(int i=0;i<roundCounter;i++) { if (BoardLEDS[i]!=userBoardLEDS[i]) { win = false; lcd.clear(); lcd.print("KHseret"); delay(1000); } } if(win==true) { lcd.clear(); lcd.print("rbe7et"); } } } roundCounter++; roundLedCounter++; roundDuration = roundDuration +1; } void TurnONLEDS() { for(int i=0;i<numberButtons;i++) { digitalWrite(ledPins[i], HIGH); } } void TurnOFFLEDS() { for(int i=0;i<numberButtons;i++) { digitalWrite(ledPins[i], LOW); } } void ResetFunc() { while(!start) { if (digitalRead(resetButtonPin) == LOW) { start = true; roundCounter = 0; roundLedCounter = 3; } } digitalWrite(resetLedPin, HIGH); }