You are on page 1of 2

#include <Keypad.

h>
const byte ROWS = 4;
const byte COLS = 4;
//define the symbols on the buttons of the keypads
char Keys[ROWS][COLS] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
//initialize an instance of class NewKeypad
Keypad key1 = Keypad(makeKeymap(Keys),rowPins,colPins,ROWS,COLS);
int motorPin1=10;
int motorPin2=11;
int motorPin3=12;
int motorPin4=13;
int count1=0;
int count2=0;
int enablePin=13;
// Define the Keymap
// Create the Keypad
void setup()
{
Serial.begin(9600);
Serial.println("Please press the keyboard:");
pinMode(motorPin1,OUTPUT);
pinMode(motorPin2,OUTPUT);
pinMode(motorPin3,OUTPUT);
pinMode(motorPin4,OUTPUT);
pinMode(enablePin,OUTPUT);
}
void loop()
{
char key = key1.getKey();
if(key!=NO_KEY)
{
Serial.print("Key Value : ");
Serial.println(key);
if((key == '3') && (count1 == 0))
{
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,LOW);
delay(3000);
count1=1;

goto motorstop1;
}
if((key=='A')&&(count2==0))
{
digitalWrite(motorPin3,HIGH);
digitalWrite(motorPin4,LOW);
delay(3000);
count2=1;
goto motorstop2;
}
if((key == '6')&&(count1==1))
{
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,HIGH);
delay(3000);
count1=0;
goto motorstop1;
}
if((key=='B')&&(count2==1))
{
digitalWrite(motorPin3,LOW);
digitalWrite(motorPin4,HIGH);
delay(3000);
count2=0;
goto motorstop2;
}
motorstop1:
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,LOW);
delay(300);
motorstop2:
digitalWrite(motorPin3,LOW);
digitalWrite(motorPin4,LOW);
delay(300);
}
}

You might also like