You are on page 1of 2

#include <Servo.

h>

Servo servo_10;

#include <Keypad.h>

const byte ROWS = 4; //four rows


const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3,2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
servo_10.attach(10, 500, 2500);
Serial.begin(9600);
pinMode(11, OUTPUT);
servo_10.write(0);

void loop() {
static String inputCode = ""; // String to store the entered code

char key = keypad.getKey();

if (key != NO_KEY) {
if (key == 'C') {
inputCode = ""; // Reset the input code if c is pressed
} else {
inputCode += key; // Append the pressed key to the input code
}

Serial.println("Input Code: " + inputCode); // Print the input code to Serial


Monitor
}

if (inputCode.length() == 1) {
if (inputCode == "B") {
servo_10.write(0);
inputCode = "";
}
if (inputCode == "A") {
digitalWrite(11, LOW);
inputCode = "";
}
if (inputCode =="C") {
inputCode="";
}

}
if (inputCode.length() == 4) {
if (inputCode =="7545") {
servo_10.write(80);
} else {
servo_10.write(0);
digitalWrite(11, HIGH);
}

inputCode = "";
}
delay(100);
}

You might also like