daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. int pos = 0;
  4. int state;
  5. int score;
  6. int dly = 5;
  7. const int Button = 8;
  8.  
  9. Servo myservo;
  10.  
  11. void setup() {
  12.   pinMode(Button, INPUT_PULLUP);
  13.   Serial.begin(9600);
  14.   myservo.attach(5);
  15. }
  16.  
  17. void CheckYourselfBeforeYouWreckYourself() {
  18.     if (state == 0 && pos >=  30 && pos <= 60) {
  19.   score = score + 1;
  20.   Serial.println("+1 punt!");
  21.   Serial.println("Je score is nu: " + score + " punten!");
  22.   }
  23.   if (state == 0 && pos >= 150  && pos <= 170) {
  24.   score = score + 2;
  25.   Serial.println("+2 punten!");
  26.   Serial.println("Je score is nu: " + score + " punten!");
  27.   }
  28.   if (state == 0 && pos >=  90 && pos <= 100) {
  29.   score = score + 1;
  30.   Serial.println("+3 punten!");
  31.   Serial.println("Je score is nu: " + score + " punten!");
  32.   }
  33. }
  34.  
  35.  
  36. void loop() {
  37.  
  38.   state = digitalRead(Button);
  39.   Serial.println(state);
  40.  
  41.   for (pos = 0; pos <= 180; pos++); {
  42.   myservo.write(pos);
  43.   CheckYourselfBeforeYouWreckYourself();
  44.   delay(dly);
  45.    
  46.   }
  47.   for (pos = 180; pos >= 0; pos--) {
  48.   myservo.write(pos);
  49.   CheckYourselfBeforeYouWreckYourself();
  50.   delay(dly);
  51.  
  52.   }
  53.  }
RAW Paste Data
Top