SHARE
TWEET

Untitled

a guest Oct 12th, 2017 55 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.  
  18. void loop() {
  19.  
  20.   state = digitalRead(Button);
  21.   Serial.println(state);
  22.  
  23.   for (pos = 0; pos <= 180; pos++); {
  24.   myservo.write(pos);
  25.   CheckYourselfBeforeYouWreckYourself();
  26.   delay(dly);
  27.    
  28.   }
  29.   for (pos = 180; pos >= 0; pos--) {
  30.   myservo.write(pos);
  31.   CheckYourselfBeforeYouWreckYourself();
  32.   delay(dly);
  33.  
  34.   }
  35.  }
  36.  
  37. void CheckYourselfBeforeYouWreckYourself() {
  38.   if (state == 0 && pos >=  30 && pos <= 60) {
  39.   score = score + 1;
  40.   Serial.println("+1 punt!");
  41.   Serial.println("Je score is nu: " + score + " punten!");
  42.   }
  43.   if (state == 0 && pos >= 150  && pos <= 170) {
  44.   score = score + 2;
  45.   Serial.println("+2 punten!");
  46.   Serial.println("Je score is nu: " + score + " punten!");
  47.   }
  48.   if (state == 0 && pos >=  90 && pos <= 100) {
  49.   score = score + 1;
  50.   Serial.println("+3 punten!");
  51.   Serial.println("Je score is nu: " + score + " punten!");
  52.   }
  53. }
RAW Paste Data
Top