#include <Keypad.h>
#include <Servo.h>
Servo servo;
void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
servo.attach(12);
//1 2 led 3 buzz 4 to 11 keypad 12 servo
}
const int rowNum = 4;
const int colNum = 4;
int x = 0;
int y = 0;
char keys[rowNum][colNum] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPin[rowNum] = {11, 10, 9, 8};
byte colPin[colNum] = {7, 6, 5, 4};
Keypad keypad = Keypad(makeKeymap(keys), rowPin, colPin, rowNum, colNum);
void loop() {
int a = analogRead(A0);
int b = analogRead(A1);
// 0 to 1023
delay(100);
char key = keypad.getKey();
int guess = key - '0';
if (key!= NO_KEY){
if (guess == 3){
digitalWrite (2, HIGH);
x = 1;
}
else{
digitalWrite (2, LOW);
tone(3, 250, 10000);
}
}
if (a >= 700 and a <= 800 and b >= 1000) {
digitalWrite (13, HIGH);
y = 1;
}
else {
digitalWrite (13, LOW);
}
if (x == 1 and y == 1) {
servo.write(180);
}
else {
servo.write(0);
}
}