SHARE
TWEET

Arduino dart trainer code

lolface Jan 21st, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <TM1637Display.h>
  2.  
  3. const int CLK = 6;
  4. const int DIO = 7;
  5. const int buttonPin1 = 2;
  6. const int buttonPin2 = 3;
  7. const int buttonPin3 = 4;
  8. const int resetPin = 5;
  9.  
  10. int buttonState1 = 0;
  11. int buttonState2 = 0;
  12. int buttonState3 = 0;
  13. int resetState = 0;
  14.  
  15. TM1637Display display(CLK, DIO);
  16.  
  17. int score = 0;
  18.  
  19. void setup() {
  20.   // put your setup code here, to run once:
  21.   pinMode(buttonPin1, INPUT_PULLUP); // use internal pullup
  22.   pinMode(buttonPin2, INPUT_PULLUP);
  23.   pinMode(buttonPin3, INPUT_PULLUP);
  24.   pinMode(resetPin, INPUT_PULLUP);
  25.   display.setBrightness(0x0a);
  26.   Serial.begin(9600);
  27. }
  28.  
  29. void loop() {
  30.  
  31.   buttonState1 = digitalRead(buttonPin1);
  32.   buttonState2 = digitalRead(buttonPin2);
  33.   buttonState3 = digitalRead(buttonPin3);
  34.   resetState = digitalRead(resetPin);
  35.   if (buttonState1 == LOW) {
  36.     score += 1;
  37.     Serial.println(score);
  38.     display.showNumberDec(score);
  39.     delay(200);
  40.   }
  41.   if (buttonState2 == LOW) {
  42.     score += 2;
  43.     Serial.println(score);
  44.     display.showNumberDec(score);
  45.     delay(200);
  46.   }
  47.   if (buttonState3 == LOW) {
  48.     score += 3;
  49.     display.showNumberDec(score);
  50.     delay(200);
  51.   }
  52.   if (resetState == LOW) {
  53.     score = 0;
  54.     Serial.println(score);
  55.     display.showNumberDec(score);
  56.     delay(200);
  57.   }
  58.   display.showNumberDec(score);
  59. }
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