Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myServo;
- const int topSwitch = 2;
- const int btmSwitch = 8;
- const int servoPin = 12;
- int topSwitchPinState = HIGH;
- int btmSwitchPinState = HIGH;
- int prevtopSwitchState = HIGH;
- int prevbtmSwitchState = HIGH;
- void setup() {
- Serial.begin(9600);
- myServo.attach(servoPin);
- myServo.write(0);
- pinMode(topSwitch,INPUT_PULLUP);
- pinMode(btmSwitch,INPUT_PULLUP);
- }
- void loop() {
- delay(10);
- if (digitalRead(topSwitch) == LOW) {
- Serial.println("Top Button Pushed");
- unsigned long startTime = millis();
- unsigned long endTime = startTime + 5000; // five extra seconds
- Serial.println("Start time: "+String(startTime));
- Serial.println("End time: "+String(endTime));
- while (1) {
- delay(10);
- if (millis() >= endTime) {
- myServo.write(90);
- Serial.println("Out of Time: Reset Switch");
- break;
- }
- if (digitalRead(btmSwitch) == LOW) {
- myServo.write(90);
- Serial.println("Bottom Switch Pressed: Reset");
- break;
- }
- } // end while
- } // end if
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement