Advertisement
Guest User

Arduino Code

a guest
Sep 14th, 2013
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Metro.h>
  2.  
  3. int button = 2;
  4. int led = 13;
  5. int points = 0;
  6. int pointState = 3;
  7.  
  8. boolean ledState = LOW;
  9.  
  10. Metro ledButton = Metro(0);
  11.  
  12. void setup()
  13. {
  14.   Serial.begin(9600);
  15.   pinMode (led, OUTPUT);
  16.   pinMode (button, INPUT);
  17. }
  18.  
  19. void loop()
  20. {
  21.   boolean buttonState = digitalRead(button);
  22.  
  23.   if (ledButton.check() == 1)
  24.   {
  25.       if (ledState == LOW)
  26.       {
  27.         ledState = HIGH;
  28.      
  29.         if (pointState == HIGH){
  30.           points++;
  31.           pointState = 3;
  32.       }
  33.       ledButton.interval(500);
  34.     }
  35.  
  36.     else
  37.     {
  38.       ledState = LOW;
  39.      
  40.       if (pointState == LOW){
  41.         points--;
  42.         pointState = 3;
  43.       }
  44.       Serial.println(points);
  45.     }
  46.   }
  47.  
  48.   if (buttonState == HIGH && ledState == HIGH)
  49.     pointState = HIGH;
  50.    
  51.   if (buttonState == HIGH && ledState == LOW)
  52.     pointState = LOW;
  53.    
  54.   digitalWrite (led,ledState);
  55. }
Advertisement
RAW Paste Data Copied
Advertisement