#include <Servo.h>
const int killswitch = 2;
const int brakeservosignal = 3;
static int state;
unsigned long lastRead;
int intervalDebounce = 50;
byte lastState = 1;
Servo brakeservo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(killswitch,INPUT);
brakeservo.attach(brakeservosignal);
brakeservo.write(90);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long now = millis();
if (now - lastRead >= intervalDebounce){
byte abyte = digitalRead(killswitch);
if (abyte != lastState){
lastRead = now;
lastState = abyte;
}
}
if (state != lastState){
Serial.print("Button:");
Serial.print(lastState);
Serial.print(" Servo:");
Serial.println(lastState ? 30 : 150);
brakeservo.write(lastState ? 30 : 150);
state = lastState;
}
}