Skip to content

Commit c864864

Browse files
committed
Fixed some issues
1 parent 81d0ec8 commit c864864

3 files changed

Lines changed: 99 additions & 26 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# SimonSays
22
Simon says for the Arduino
3+
4+
Circuit Diagram
5+
---------------
6+
![Circuit Diagram](https://github.com/AlexMainstone/SimonSays/blob/master/diagram.png)
7+
8+
Adding Additional LED's
9+
-----------------------
10+
Simply add an LED and PushButton to the circuit parallel to the others.
11+
12+
Now just add the port of the LED to:
13+
14+
15+
16+
Features
17+
--------
18+
- Extensibility: More LEDs and switches can be added to the circuit and an array in the code. The code is written with a non-specific led amount in mind.
19+
- Simplicity: An easy game to understand, with a simple design
20+
- Multiple levels: The game continues to level 100, this can be changed in code easily by changing the constant variable in the code.
21+
- Failure: The game clearly states failure by flashing all the LEDs
22+
- Makes use of Push Buttons and LEDs
23+
- Modular code
24+
25+
Instructions
26+
------------
27+
- The goal of the game is to copy the sequence of lights.
28+
- Each button corresponds with an LED, the goal of the game is to remember the sequence of lights presented by the arduino and copy it.
29+
- The arduino will display a light, press the button corresponding with that light.
30+
- The computer will then add another light to the sequence, you must then repeat the sequence using the buttons.
31+
- If you fail to enter the sequence correctly, all of the LEDs will light up, meaning that you have failed! The game will then restart.

Simon_Says.ino

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Author: Alex Mainstone
3+
* Username: eeuae3
4+
* Date: 11/02/2018
5+
*/
6+
7+
//This will make my code extendable, allowing for users to add their own switch and LED
8+
const int LED_NUM = 4;
9+
const int leds[LED_NUM] = {3,4,5,2};
10+
const int switches[LED_NUM] = {8,7,6,9};
11+
12+
int level = 0; //the number of leds in the level
13+
int current = 0; //current place in order
14+
const int MAX_LEVEL = 100; //The maximum level
15+
int order[MAX_LEVEL] = {};
16+
17+
void setup() {
18+
for(int i = 0; i < LED_NUM; i++){ //Enable all LED's and Buttons
19+
pinMode(leds[i], OUTPUT);
20+
pinMode(switches[i], INPUT);
21+
}
22+
compTurn();
23+
}
24+
25+
//Flashes the desired LED
26+
void flashLED(int LED) {
27+
delay(1000);
28+
digitalWrite(LED, HIGH);
29+
delay(1000);
30+
digitalWrite(LED, LOW);
31+
}
32+
33+
//Generates the next member of the sequence
34+
void compTurn() {
35+
current = 0;
36+
order[level++] = leds[rand() % LED_NUM];
37+
for(int i = 0; i < level; i++) {
38+
flashLED(order[i]);
39+
}
40+
}
41+
42+
//Flashes all LEDs
43+
void fail() {
44+
for(int i = 0; i < LED_NUM; i++) {
45+
digitalWrite(leds[i], HIGH);
46+
}
47+
delay(1000);
48+
for(int i = 0; i < LED_NUM; i++) {
49+
digitalWrite(leds[i], LOW);
50+
}
51+
level = 0;
52+
compTurn();
53+
}
54+
55+
void loop() {
56+
for(int i = 0; i < LED_NUM; i++) {
57+
int state = digitalRead(switches[i]);
58+
if(state == HIGH){
59+
while(state == HIGH) { state = digitalRead(switches[i]); } //Wait until the button is released
60+
if(order[current] == leds[i]) {
61+
current++;
62+
if(current == level){
63+
compTurn();
64+
}
65+
} else {
66+
fail();
67+
}
68+
}
69+
}
70+
}

alex_s_code.ino

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)