Exit Full View

simon.pde

/*

This is a the classic "copy the sequence of coloured lights". Originally called Simon.

There are coloured lights, each with its own button. The computer picks a random colour, which the player then has to copy (by pressing that colour's button). The computer then picks another colour, and adds it to the original. Now the player has to copy both colours. This continues, with the sequence getting longer and longer until the player gets it wrong, at which point the game is over.

  • /

int COLOURS = 4;

int ledPins4= {6,7,8,9}; int buttonPins4 = {2,3,4,5}; int speakerPin = 10; int speedPin = 0;

int NONE = -1; int colour = NONE; // The currently lit LED. 0 to 3, or NONE when no colour is lit.

int tones4 = {700,800,900,1000}; // Each colour has a different tone

/* "state" determines what is to happen next, and the following are the vaues that "state" can have. The numbers don't mean anything (as long as they are all different).

  • /

int STATE_NONE = -1;int STATE_RESTART = 1; // Press any key to start a new game.int STATE_LISTEN = 2; // The program plays the sequence that the player will soon repeat.int STATE_REPEAT = 3; // The player is trying to repeat the sequence.

int state = STATE_RESTART;

const int MAX_SEQUENCE = 100; int sequenceMAX_SEQUENCE; // The list of random colours (0..3) in the sequence so far. int sequenceSize = 0; // The number of items in the sequence so far int repeatIndex = 0; // The number of colours the player has repeated.

int delayDuration = 500;

int awaitState = HIGH;

void setup() { Serial.begin( 9600 );

for ( int i = 0; i < COLOURS; i ) { pinMode( ledPinsi, OUTPUT ); pinMode( buttonPinsi, INPUT ); digitalWrite( ledPinsi, LOW ); // All lights off at the beginning } pinMode( speakerPin, OUTPUT ); }

Error at line 52, 35