Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 26th, 2014  |  syntax: C  |  size: 1.05 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #define TARGET 32
  2. #define TIMELIMIT_MILLIS 1000
  3.  
  4. int leds[5] = {13, 12, 11, 10, 9};
  5. int buttons[5] = {8, 7, 6, 5, 4};
  6. int niveau = 0;
  7. int ledList[TARGET];
  8.  
  9. void setup() {
  10.         for(int i = 0; i<5;i++){
  11.                 pinMode(leds[i], OUTPUT);
  12.                 pinMode(buttons[i],INPUT); //Initializing button as input
  13.                 digitalWrite(buttons[i],HIGH); //Enabling the internal Arduino pullup-resistor
  14.         }
  15. }
  16. void ledSequence()
  17. {
  18.         for(int i=0; i<=niveau; i++)
  19.         {
  20.                 digitalWrite(ledList[i + 8],HIGH);
  21.                 delay(1000);
  22.                 digitalWrite(ledList[i + 8],LOW);
  23.                 delay(1000);
  24.         }
  25. }
  26. void loop()
  27. {
  28.         ledList[niveau] = random(1 , 5);
  29.         ledSequence();
  30.         delay(2000);
  31.         niveau++;
  32.         /*
  33.         IF niveau EQUALS TARGET
  34.         //Game is won, display it somehow
  35.         ELSE
  36.         WRONGCOUNT = 0
  37.         FOR CURRENT_POSITION = 0; CURRENT_POSITION < niveau; CURRENT_POSITION++
  38.                 TIMESTAMP = CURRENT_TIME_MILLIS()
  39.                 BOOLEAN CORRECTED = FALSE
  40.                 WHILE TIMESTAMP < TIMELIMIT_MILLIS
  41.                         IF(READ(ledList[CURRENT_POSITION]-1))
  42.                                 CORRECTED = TRUE
  43.         IF WRONGCOUNT > 0
  44.         //You failed!
  45.         ELSE
  46.         //You did it! Time to loop again
  47.         */
  48. }