/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2;
int potpin = 0;
int potpin2 = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int spe = 0;
void setup() {
Serial.begin(9600);
pinMode(10, INPUT_PULLUP);
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo2.attach(8);
}
bool ignmem = false;
void loop() {
start:
val = 0;
servo2.write(val);
servo1.write(val);
bool btnState = !digitalRead(10);
if (btnState && !ignmem) { // обработчик нажатия
ignmem = true;
Serial.println("Ignition");
}
else {return 0;}
hello:
val=0;
servo2.write(val);
servo1.write(val);
delay(1000);
val=180;
servo2.write(val);
servo1.write(val);
delay(1000);
val =0;
servo2.write(val);
servo1.write(val);
delay(1000);
Serial.println(" Work ");
goto work;
work:
val = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
spe = analogRead(A1);
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
spe = map(spe, 0, 1023, 0, 180);
servo2.write(val); // sets the servo position according to the scaled value
servo1.write(spe);
btnState = !digitalRead(10);
if (!btnState && ignmem) { // обработчик отпускания
ignmem = false;
Serial.println("Ignition off");
delay(1000);
goto start;
}
goto work;
}