-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d85b65
Showing
6 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
/* | ||
REFERENCE | ||
digital 6 --> 0 | ||
digital 7 --> 1 | ||
digital 8 --> 2 | ||
digital 9 --> 3 | ||
*/ | ||
|
||
#define debug false | ||
|
||
/* game */ | ||
boolean started = false; | ||
|
||
/* LEDS */ | ||
int ledOnTime = 300; | ||
int highLeds[20]; | ||
int yourLeds[20]; | ||
int index = 0; | ||
int indexHighLeds = 1; | ||
boolean finishedArray = false; | ||
|
||
void randomStartStage(); | ||
void startFinishGame(); | ||
void startLeds(int port, int code); | ||
void showLEDS(); | ||
void getYourLEDS(); | ||
void displayLed(int port); | ||
void gameOver(); | ||
void restart(); | ||
|
||
void setup() { | ||
for (int i = 6; i < 10; i++){ pinMode(i, OUTPUT); } | ||
pinMode(10, INPUT_PULLUP); | ||
for (int i = 2; i < 6; i++){ pinMode(i, INPUT_PULLUP); } | ||
Serial.begin(9600); | ||
} | ||
|
||
|
||
void loop() { | ||
if(!started){ randomStartStage(); } | ||
Serial.println("clicado --> "); | ||
Serial.print(digitalRead(10)); | ||
Serial.print(digitalRead(5)); | ||
Serial.print(digitalRead(4)); | ||
Serial.print(digitalRead(3)); | ||
Serial.print(digitalRead(2)); | ||
|
||
if(debug){ | ||
Debug(); | ||
}else{ | ||
if(digitalRead(10) == HIGH && started == false){ startFinishGame(); } | ||
if(digitalRead(10) == LOW) { | ||
Serial.println(" -- started -- "); | ||
started = true; | ||
} | ||
|
||
if (started){ | ||
if(!finishedArray){ showLEDS(); } | ||
|
||
if(index <= indexHighLeds){getYourLEDS(); } | ||
else{ next(); } | ||
|
||
delay(200); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
void randomStartStage(){ | ||
highLeds[0] = random(4); | ||
highLeds[1] = random(4); | ||
Serial.println("<----- Random Start Stage ----->"); | ||
Serial.print(highLeds[0]); | ||
Serial.print(highLeds[1]); | ||
for (int i = 2; i < 20; i++){ highLeds[i] = -1; } | ||
} | ||
|
||
void startFinishGame(){ | ||
for (int i = 6; i < 10; i++){ | ||
digitalWrite(i, HIGH); | ||
delay(600); | ||
} | ||
for (int i = 6; i < 10; i++){ | ||
digitalWrite(i, LOW); | ||
delay(600); | ||
} | ||
} | ||
|
||
void gameOver(){ | ||
digitalWrite(6, HIGH); | ||
digitalWrite(7, HIGH); | ||
digitalWrite(8, HIGH); | ||
digitalWrite(9, HIGH); | ||
delay(3000); | ||
digitalWrite(6, LOW); | ||
digitalWrite(7, LOW); | ||
digitalWrite(8, LOW); | ||
digitalWrite(9, LOW); | ||
restart(); | ||
} | ||
|
||
void restart(){ | ||
started = false; | ||
|
||
ledOnTime = 300; | ||
for(int j = 0; j < 21; j++){ | ||
highLeds[j] = -1; | ||
yourLeds[j] = -1; | ||
} | ||
index = 0; | ||
indexHighLeds = 1; | ||
finishedArray = false; | ||
} | ||
|
||
void startLeds(int port, int code){ | ||
Serial.println("cosisosososo --> "); | ||
Serial.print(index, indexHighLeds); | ||
Serial.print(code); | ||
if(highLeds[index] != code){ gameOver(); } | ||
else{ | ||
if(index == 19){ win(); } | ||
else{ | ||
digitalWrite(port, HIGH); | ||
yourLeds[index] = code; | ||
index++; | ||
} | ||
} | ||
} | ||
void Debug(){ | ||
|
||
if(digitalRead(5) == LOW){ | ||
digitalWrite(6, HIGH); | ||
delay(1000); | ||
digitalWrite(6, LOW); | ||
} | ||
|
||
if(digitalRead(4) == LOW){ | ||
digitalWrite(8, HIGH); | ||
delay(1000); | ||
digitalWrite(8, LOW); | ||
} | ||
|
||
if(digitalRead(3) == LOW){ | ||
digitalWrite(9, HIGH); | ||
delay(1000); | ||
digitalWrite(9, LOW); | ||
} | ||
if(digitalRead(2) == LOW){ | ||
digitalWrite(7, HIGH); | ||
delay(1000); | ||
digitalWrite(7, LOW); | ||
} | ||
} | ||
void next(){ | ||
index = 0; | ||
indexHighLeds ++; | ||
int nextLed = random(4); | ||
highLeds[indexHighLeds] = nextLed; | ||
finishedArray = false; | ||
digitalWrite(6, LOW); | ||
digitalWrite(7, LOW); | ||
digitalWrite(8, LOW); | ||
digitalWrite(9, LOW); | ||
} | ||
//6, 8, 9, 7 | ||
void win(){ | ||
digitalWrite(6, HIGH); | ||
delay(600); | ||
digitalWrite(6, LOW); | ||
|
||
digitalWrite(8, HIGH); | ||
delay(600); | ||
digitalWrite(8, LOW); | ||
|
||
digitalWrite(9, HIGH); | ||
delay(600); | ||
digitalWrite(9, LOW); | ||
|
||
digitalWrite(7, HIGH); | ||
delay(600); | ||
digitalWrite(7, LOW); | ||
|
||
delay(100); | ||
restart(); | ||
} | ||
|
||
void showLEDS(){ | ||
delay(500); | ||
|
||
int i = 0; | ||
|
||
while (!finishedArray){ | ||
if(highLeds[i] == 0){ displayLed(6); } | ||
else if(highLeds[i] == 1){ displayLed(7); } | ||
else if(highLeds[i] == 2){ displayLed(8); } | ||
else if(highLeds[i] == 3){ displayLed(9); } | ||
else if(highLeds[i] == -1){ finishedArray = true; } | ||
|
||
delay(100); | ||
i ++; | ||
} | ||
} | ||
|
||
|
||
void getYourLEDS(){ | ||
Serial.println("index"); | ||
Serial.println(index); | ||
if(digitalRead(5) == LOW){ startLeds(6, 0); } | ||
else { digitalWrite(6, LOW); } | ||
|
||
if(digitalRead(4) == LOW){ startLeds(8, 2); } | ||
else { digitalWrite(8, LOW); } | ||
|
||
if(digitalRad(3) == LOW){ startLeds(9, 3); } | ||
else { digitalWrite(9, LOW); } | ||
|
||
if(digitalRead(2) == LOW){ startLeds(7, 1); } | ||
else { digitalWrite(7, LOW); } | ||
} | ||
|
||
void displayLed(int port){ | ||
digitalWrite(port, HIGH); | ||
delay(ledOnTime); | ||
digitalWrite(port, LOW); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Genius with arduino | ||
|
||
In this repo, you'll see my version of Genius toy. | ||
[![Genius Estrela](./assets/genius.png)](https://www.estrela.com.br/jogo-genius-estrela-100543353_est_pai/p) | ||
|
||
It was created using arduino and some eletronic components, like `push buttons, wires and LEDs`. | ||
|
||
[video] | ||
|
||
I created this project to a technology week from my former school. I was coursing eletronics, and as a way to show to new students what we were doing in this course, we made this project. | ||
|
||
With the circuit and the code done, we made a simple box to put all inside, to abstract all the boring part, and let everyone to have fun with. | ||
|
||
![Project with case 1](./assets/01.jpg) | ||
![Project with case 2](./assets/02.jpg) | ||
![Project with case 3](./assets/03.jpg) | ||
|
||
## How to play | ||
In this game you need to follow the light sequence, if you miss the sequence, you lose. | ||
|
||
To start, hold the side button untill top LEDs turn off, then click the buttons on the sequence. | ||
|
||
[video1] | ||
|
||
If you lose, all the LEDs will be turn on and you need to restart pressing the side button. | ||
|
||
[video2] | ||
|
||
|
||
|