Hey guys i'm trying imitate this code that has already been created by another user but do not get what some specific parts of the code are doing. It would be a great help if you could explain to me what the specific parts that i will highlight are doing in the code.
The code is for a lock that opened when a certain sequence of keys are pressed, these keys are linked to notes of a piano thus you have to play a tune to open the lock. The link to the other users project is http://www.instructables.com/id/Piano-Safe-With-Melody-key/
What I don't get is the if statements at the bottom where if "(button > 150){tone(piezo, 330); toon=7; volgende=false"
and/or
the whole of the decision making part at the bottom that starts with if (teller == 1 && toon == 2 && volgende == true){teller = 2; volgende = false;}
If possible could you explain what is going on here please
thank you
Here is the code:
// gcceddFbbdc 25576684465
#include
Servo myservo;
int buttonPin = A0;
int button = 0;
int piezo = 3;
int toon = 0; // f=1 g=2 a=3 b=4 c=5 d=6 e=7 F=8
int volgende = true;
int teller = 1;
void setup() {
// Serial.begin(9600); //debugging
pinMode(13, OUTPUT);
myservo.attach(9);
myservo.writeMicroseconds(1000); }
void loop() {
delay(30); //debounce
button = analogRead(buttonPin);
//Serial.print(toon);
//Serial.print(volgende);
//Serial.println(button); //debugging
if (button > 400){tone(piezo, 349); toon=8; volgende=false;} // F
else {if (button > 150){tone(piezo, 330); toon=7; volgende=false;} // e
else {if (button > 100){tone(piezo, 294); toon=6; volgende=false;} // d
else{if (button > 80){tone(piezo, 262); toon=5; volgende=false;} // c
else{if (button > 60){tone(piezo, 247); toon=4; volgende=false;} // b
else{if (button > 48){tone(piezo, 220); toon=3; volgende=false;} // a
else{if (button > 38){tone(piezo, 196); toon=2; volgende=false;} // g
else{if (button > 20){tone(piezo, 175); toon=1; volgende=false;} // f
else{noTone(piezo); volgende=true;}}}}}}}}
if (teller == 1 && toon == 2 && volgende == true){teller = 2; volgende = false;}
if (teller == 2 && toon == 5 && volgende == true){teller = 3; volgende = false;} else{if(volgende == true && teller == 2 && toon != 2){teller = 1;}}
if (teller == 3 && toon == 5 && volgende == true){teller = 4; volgende = false;} else{if(volgende == true && teller == 3 && toon != 2){teller = 1;}}
if (teller == 4 && toon == 7 && volgende == true){teller = 5; volgende = false;} else{if(volgende == true && teller == 4 && toon != 7 && toon != 5){teller = 1;}}
if (teller == 5 && toon == 6 && volgende == true){teller = 6; volgende = false;} else{if(volgende == true && teller == 5 && toon != 7){teller = 1;}}
if (teller == 6 && toon == 6 && volgende == true){teller = 7; volgende = false;} else{if(volgende == true && teller == 6 && toon != 7){teller = 1;}}
if (teller == 7 && toon == 8 && volgende == true){teller = 8; volgende = false;} else{if(volgende == true && teller == 7 && toon != 6 && toon != 8){teller = 1;}}
if (teller == 8 && toon == 4 && volgende == true){teller = 9; volgende = false;} else{if(volgende == true && teller == 8 && toon != 8){teller = 1;}}
if (teller == 9 && toon == 4 && volgende == true){teller = 10; volgende = false;} else{if(volgende == true && teller == 9 && toon != 8){teller = 1;}}
if (teller == 10 && toon == 6 && volgende == true){teller = 11; volgende = false;} else{if(volgende == true && teller == 10 && toon != 4){teller = 1;}}
if (teller == 11 && toon == 5 && volgende == true){teller = 12; volgende = false;} else{if(volgende == true && teller == 11 && toon != 6){teller = 1;}}
if(teller == 12 && volgende == true){ teller = 13; digitalWrite(13, HIGH); myservo.writeMicroseconds(2000); delay(5000);} //2000 is the value for the open servo
if(teller == 13 && volgende == true && toon != 5){ digitalWrite(13, LOW); teller = 1; myservo.writeMicroseconds(1000);} //1000 is the value for the closed servo
}