#include <Keypad.h>
int motorPin1 = 5;
int motorPin2 = 6;
const byte rows = 2;
const byte cols = 1;
char hexaKeys[rows][cols] = {{'2'}, {'1'}};
byte rowPins[rows] = {3, 2};
byte colPins[cols] = {4};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, rows, cols);
void setup()
{
Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop()
{
char customKey = customKeypad.getKey();
switch (customKey)
{
case '1':
Serial.println("Rotates to left");
rotateLeft();
break;
case '2':
Serial.println("Rotates to right");
rotateRight();
break;
}
}
void rotateLeft()
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(5000); // Motoru 5 saniye boyunca döndür
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}
void rotateRight()
{
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, LOW);
delay(5000); // Motoru 5 saniye boyunca döndür
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}