-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOT_KEYPAD.ino
73 lines (64 loc) · 1.71 KB
/
BOT_KEYPAD.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <Key.h>
#include <Keypad.h>
const byte row=4;
const byte column=4;
char key[row][column]={{'1', '2', '3','U'},
{'4', '5', '6', 'D'},
{'7', '8', '9', 'R'},
{'*', '0', 'S', 'L'}};
byte rowPins[row]={2, 3, 4, 5};
byte colPins[column]={0,0 ,11,6};
Keypad keypad=Keypad(makeKeymap(key), rowPins, colPins, row, column);
#define motorpin1 7
#define motorpin2 8
#define motorpin3 9
#define motorpin4 10
void setup() {
pinMode(motorpin1, OUTPUT);
pinMode(motorpin2, OUTPUT);
pinMode(motorpin3, OUTPUT);
pinMode(motorpin4, OUTPUT);
Serial.begin(9600);
}
void loop() {
char state=keypad.getKey();
while(Serial.available()){
char c=Serial.read();
if(c=='#')
{break;}
state+=c;
}
Serial.println(state);
if(state=='D')
{ digitalWrite(motorpin1, HIGH);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, HIGH);
digitalWrite(motorpin4, LOW);
}
if(state=='S')
{ digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, LOW);
}
if(state=='U')
{ digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, HIGH);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, HIGH);
}
if(state=='L')
{ digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, HIGH);
}
if(state=='R')
{
digitalWrite(motorpin1, LOW);
digitalWrite(motorpin2, HIGH);
digitalWrite(motorpin3, LOW);
digitalWrite(motorpin4, LOW);
}
// put your main code here, to run repeatedly:
}