short topRow = 3;
short btmRow = 2;
short aPin = A0;
short lock = 0; //defines the lock variable
void setup() {
// put your setup code here, to run once:
pinMode(topRow, INPUT_PULLUP);
pinMode(btmRow, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int angle = analogRead(aPin);
delay(10);
//-------------------------------------------
if(angle < 490){
if(digitalRead(topRow) == LOW){
if(lock != 1){
Serial.println("gear 1");
lock = 1;
}
}
if(digitalRead(btmRow) == LOW){
if(lock != 2){
Serial.println("gear 2");
lock = 2;
}
}
}
//--------------------------------------------
if(530 > angle && angle > 490){
if(digitalRead(topRow) == LOW){
if(lock != 3){
Serial.println("gear 3");
lock = 3;
}
}
if(digitalRead(btmRow) == LOW){
if(lock != 4){
Serial.println("gear 4");
lock = 4;
}
}
}
//---------------------------------------------
if(570 > angle && angle > 530){
if(digitalRead(topRow) == LOW){
if(lock != 5){
Serial.println("gear 5");
lock = 5;
}
}
if(digitalRead(btmRow) == LOW){
if(lock != 6){
Serial.println("gear 6");
lock = 6;
}
}
}
//----------------------------------------------
if(angle > 570){
if(digitalRead(topRow) == LOW){
if(lock != 7){
Serial.println("gear 7");
lock = 7;
}
}
if(digitalRead(btmRow) == LOW){
if(lock != 8){
Serial.println("gear R");
lock = 8;
}
}
}
//----------------------------------------------
if(digitalRead(topRow) == HIGH && digitalRead(btmRow) == HIGH){
if(lock != 0){
Serial.println("gear N");
lock = 0;
}
}
}