Friday, May 2, 2014

Who does not remember this classic memory game? The player must repeat the sequence ledon led shown


Who does not remember this classic memory game? The player must repeat the sequence ledon led shown, ledon led and each hit gets harder. A good hobby and a great exercise for your head! The game saves the highscore. So you can check which was his record. Simply connect the game with the green LED button. This will cause the LED to blink the number of times the record ledon led score. If you want to reset the memory, hold down until the LED stops flashing ledon led button. And when a record score is beaten, the end of the game the green LED flashes. So the goal is to see the LED flashing green! It's scoring record beaten! I made the circuit using the Arduino platform, and mounted on a phenolite of 8x7 cm board.
/ * ----------------------------- Program: GENIUS ledon led (SIMON GAME) Author: Santino Couto Date: 04.04.2014 - ---------------------------- * / # include <EEPROM.h> / / Library of EEPROM unsigned long previousMillis = 0; long interval = 1000; / / Time interval within ledon led the loop. 1000 milliseconds (1 second) TimeControl int = 0; / / Controls the time of idleness led int [4] = {12, 11, 10, 9}; / / Int LED pins but [4] = {5, 6, 7, 8}; / / Pins sequence of buttons int [100]; / / Array with the sequel to the game countGame int = 0; countInput int = 0; MaxScore EEPROM.read = int (0); / / Returns the value of the score stored in EEPROM boolean play = true; / * SETUP ----- ----- * / void setup () {for (int i = 0; i <4; ledon led i + +) {pinMode (led [i], OUTPUT); / / Set the pins as output pinMode (but [i], INPUT); / / Set the pin as input} randomSeed (analogRead (0)); / / For random not repeat ledon led the sequence score (); / / Function to check and display the score start (); / / Start the game} / * MAIN LOOP ----- ----- * / void loop () {unsigned long currentMillis = millis (); / / Interval 1 second if (currentMillis - previousMillis> interval) {= previousMillis currentMillis; TimeControl + +; / / Increments the control variable time if (TimeControl> = 10) {/ / Getting 10 seconds without pressing, the game starts again start (); }} If (play == true) {game (); Else {player} (); }} / * ----- TOSS GAME ----- * / void game () {+ + countGame; sequence [countGame] ledon led = random (4); / / 0 to 3 for (int i = 1, i <= countGame, i + +) {digitalWrite (LED [sequence [i]], HIGH); delay (400); digitalWrite (led [sequence [i]], LOW); delay (150); Play = false}; } / * ----- PLAYER ----- * / void Player () {int input = 4; int t = 300; / / Read buttons for (int b = 0, b <4, b + +) {if (digitalRead (but [b]) == 1) {digitalWrite (led [b], HIGH); delay (t); input = b; }} / / Clears all LEDs for (int i = 0; i <4; i + +) {digitalWrite (led [i], LOW); } If (! Input = 4) {/ / If a button was pressed TimeControl = 0; countInput + +; if (! Sequence [countInput] = input) {/ / Missed the delay sequence (t); blinkLeds (8, 150); / / Blink the LEDs indicating the error score (); / / Check to score delay (3000); start (); / / Start the game again} else if (countInput countGame ==) {/ / It hit the countInput sequence = 0; play = true; delay (t); blinkLeds (1, 1000); }}} / * ----- SEQUENCE OF INITIAL FLASHING LEDS ----- * / void start () {countGame = 0; countInput = 0; TimeControl = 0; play = true; / / Blink the LEDs randomly for (int i = 0; i <15; i + +) {int x = random (4); digitalWrite (led [x], HIGH); delay (20); digitalWrite (led [x], LOW); delay (100); } / / Clears and illuminates the LEDs in sequence for (int y = 0; y <3, y + +) {for (int i = 0; i <4; i + +) {digitalWrite (led [i], LOW); delay (80); } For (int i = 0; i <4; i + +) {digitalWrite (led [i], HIGH); &

No comments:

Post a Comment