Hello guys, I'm still a beginner in the language and I'm looking for some help on this, insert a button on the pin 11 so that clicking it Microservo the return to the starting position, as you can do this? another problem is that the Microservo "vibrates" because I believe that you do not in the ideal position, how do I resolve this? help guys.
Giacomo.
#include <Keypad.h>
#include <Servo.h>
#define LED 13 // Green Led
#define LED 12// Red Led
int Buzzer = 9;
Servo myservo;
const byte ROWS = 4;
const byte COLS = 3;
char keyInsert[5];
int i = 0;
int j = 0;
int s = 0;
int x = 0;
char code[5] = "1997";
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
myservo.attach(10);
}
void loop() { //insert PIn to verify
char key = keypad.getKey();
if (i == 0) {
i++;
}
if (key != NO_KEY && j < 4) {
Serial.print("*");
//Serial.println(key);
keyInsert[j] = key;
j++;
}
if (key == '*') { // Verifyng the code
delay(100);
for (s = 0; s < 4; s++) {
if (keyInsert[s] == code[s]) {
x++;
}
}
if (x == 4) { //Password Correct
Serial.begin(9600);
digitalWrite(13, HIGH);
digitalWrite(9, HIGH);
delay(50);
digitalWrite(9, LOW);
delay(100);
delay(400);
digitalWrite(13, LOW);
myservo.write(0);
delay(1000);
} else { //Password Wrong
digitalWrite(12, HIGH);
delay(400);
x = 0;
i = 0;
j = 0;
digitalWrite(12, LOW);
}
}
if (key == '#') {
x = 0;
i = 0;
j = 0;
}
}