SHARE
TWEET

Race to the LED (Arduino code)

a guest Nov 27th, 2014 513 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  // RACE TO THE LED!
  2.  
  3.  const int button1 = 8;
  4.  const int button2 = 4;
  5.  const int led1 = 9;
  6.  const int led2 = 5;
  7.  
  8.  int goal = 50;
  9.  int state1 = 0;
  10.  int state2 = 0;
  11.  
  12.  int counter1 = 0;
  13.  int counter2 = 0;
  14.  
  15.  
  16.  void setup() {
  17.  
  18.   pinMode(button1, INPUT);
  19.   pinMode(button2, INPUT);
  20.   pinMode(led1, OUTPUT);
  21.   pinMode(led2, OUTPUT);
  22.    
  23.  }
  24.  
  25.  void loop() {
  26.  
  27.    state1 = digitalRead(button1);
  28.    state2 = digitalRead(button2);  
  29.    
  30.    if(state1 == HIGH) {
  31.      counter1 = counter1 + 1;
  32.      delay(200);
  33.    }
  34.    
  35.    if(state2 == HIGH) {
  36.      counter2 = counter2 + 1;
  37.      delay(200);
  38.    }
  39.        
  40.    if (counter1 == goal) {
  41.      digitalWrite(led1, HIGH);
  42.    }
  43.    
  44.    if (counter2 == goal) {
  45.      digitalWrite(led2, HIGH);
  46.    }  
  47.      
  48.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top