#include <Servo.h>
Servo myServo;
const int piezo = A0;
const int switchPin = 2;
const int yellowLed = 3;
const int greenLed = 4;
const int redLed = 5;
int knockVal;
int switchval;
const int quietKnock = 10;
const int loudKnock = 100;
boolean locked = false;
int numberOfKnocks = 0;
void setup(){
myServo.attach(9);
pinMode(yellowLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
digitalWrite(greenLed, HIGH);
myServo.write(0);
Serial.println("The box is unlocked!");
}
void loop(){
if(locked == false) {
switchVal = digitalRead(switchPin);
if(switchval == HIGH){
locked = true;
digitalWrite(greenLed ,LOW);
digitalWrite(redLed ,HIGH);
myServo.write(90);
Serial.println("The box is locked!")
delay (1000);
}
}
if(numberOfKnocks < 3 && knockVal > 0){
if(checkForKnock(kncokVal) == true){
numberOfKnocks++;
}
Serial.print(3-numberOfKnocks);
Serial.println(" more knocks to go");
}
if(numberOfKnocks >= 3){
locked = false;
myServo.write(0);
delay(20);
digitalWrite(greenLed,HIGH);
digitalWrite(redLed,LOW);
Serial.println("The box is unlocked");
}
}
}
boolean checkForKnock(int value){
if(value > quietKnock && value < loudKnock){
digitalWrite(yellowLed, HIGH);
delay(50);
digitalWrite(yellowLed, LOW);
Serial.print("Valid knock of value ");
Seial.println(value);
return true;
}
else {
Serial.print( "Bad knock value ");
Serial.println(value);
return false;
}
}
// Sorry, im new with this, so i just need help with finding what the error is, and how to fix it
knock_lock.ino: In function 'void loop()':
knock_lock:27: error: 'switchVal' was not declared in this scope
knock_lock:34: error: expected `;' before 'delay'
knock_lock:38: error: 'kncokVal' was not declared in this scope
knock_lock.ino: At global scope:
knock_lock:53: error: expected declaration before '}' token