Hey guys i am trying to recreate a game I saw on an old post:
http://forum.arduino.cc/index.php?topic=7697.0
I can get the game to work, but I really don't know what much of the code means. I know the basics it really starts to confuse me with the "int ledPins" and between the whole void loop and endFunction. If you guys could please try and explain this all to me (preferably everything, but only what I listed is needed) It would be greatly appreciated.
Also I am using the serial monitor on the arduino mac app and it is only displaying two letters when the game is over. Any help would be appreciated.
I will also attach my setup.
Code:
#define BUTTON 2
#define LED 0
int ledPins[8] = {3, 4, 5, 6, 7, 8, 9, 10};
double tempo = 300;
int score = 0;
boolean blueLed = false;
void interrupt();
void endFunction();
void setup() {
for ( int i = 0 ; i < 8 ; i++ ) {
pinMode( ledPins , OUTPUT );
- }*
- pinMode( LED , OUTPUT );*
- pinMode( BUTTON , INPUT );*
- attachInterrupt( 0 , interrupt , FALLING );*
}
void loop() { - for ( int i = 0 ; i < 7 ; i++ ) {*
_ digitalWrite( ledPins , HIGH );_
* delay( tempo );*
_ digitalWrite( ledPins , LOW );
* }
digitalWrite( ledPins[7] , HIGH);
blueLed = true;
delay( tempo );
digitalWrite( ledPins[7] , LOW);
blueLed = false;
for ( int i = 6 ; i > 0 ; i-- ) {
digitalWrite( ledPins , HIGH );
delay( tempo );
digitalWrite( ledPins , LOW );
}
}
void endFunction() {
Serial.begin(9600);
Serial.println("game over");
Serial.print( "Your score: " );
digitalWrite( LED , HIGH );
while (1) {
//game over*
* }
}
void interrupt() {
delayMicroseconds(20000);
if ( digitalRead( BUTTON ) == HIGH ) {
return;
}
tempo = tempo * 9 / 10;
if ( blueLed ) {
score++;
}
else {
endFunction();
}
}*_