Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int pos = 0;
- int state;
- int score;
- int dly = 5;
- const int Button = 8;
- Servo myservo;
- void setup() {
- pinMode(Button, INPUT_PULLUP);
- Serial.begin(9600);
- myservo.attach(5);
- }
- void loop() {
- state = digitalRead(Button);
- Serial.println(state);
- for (pos = 0; pos <= 180; pos++); {
- myservo.write(pos);
- CheckYourselfBeforeYouWreckYourself();
- delay(dly);
- }
- for (pos = 180; pos >= 0; pos--) {
- myservo.write(pos);
- CheckYourselfBeforeYouWreckYourself();
- delay(dly);
- }
- }
- void CheckYourselfBeforeYouWreckYourself() {
- if (state == 0 && pos >= 30 && pos <= 60) {
- score = score + 1;
- Serial.println("+1 punt!");
- Serial.println("Je score is nu: " + score + " punten!");
- }
- if (state == 0 && pos >= 150 && pos <= 170) {
- score = score + 2;
- Serial.println("+2 punten!");
- Serial.println("Je score is nu: " + score + " punten!");
- }
- if (state == 0 && pos >= 90 && pos <= 100) {
- score = score + 1;
- Serial.println("+3 punten!");
- Serial.println("Je score is nu: " + score + " punten!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement