#include <Servo.h>
Servo myservo;
const int buttonPin1 = 12;
const int buttonPin2 = 8;
boolean button1_SET = false;
boolean button2_SET = false;
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
myservo.attach(6);
Serial.begin(115200);
Serial.println("RUNNING");
myservo.write(90); // start pozicia
}
void loop() {
if (!button1_SET) {
int reading1 = !digitalRead(buttonPin1);
if (reading1) {
Serial.println("BUTTON 1 ENGAGED");
button1_SET = true;
myservo.write(0);
delay(100);
}
}
if (!button2_SET) {
int reading2 = !digitalRead(buttonPin2);
if (reading2) {
Serial.println("BUTTON 2 ENGAGED");
button2_SET = true;
myservo.write(180);
delay(100);
}
}
if (button1_SET && button2_SET) {
Serial.println("RESETTING");
myservo.write(90);
button1_SET = false;
button2_SET = false;
delay(100);
}
}Kliknutím na tlačidlo sa imituje pulz z IR snímača prekážky pri detekcii rušňa.