-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypad.ino
77 lines (62 loc) · 1.36 KB
/
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
74
75
76
77
#include <Password.h>
const int led = 2;
Password password = Password("12345");
int sensorValue = 0; // value read from the pot
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
if(sensorValue > 0) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
// change the analog out value:
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.println(keyval(sensorValue));
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
char keyval(int val) {
if (val < 5)
return 'N';
if(val < 60)
return 'A';
if(val < 90)
return 'B';
if(val < 110)
return 'C';
if(val < 130)
return '3';
if (val < 170)
return '6';
if(val < 200)
return 'D';
if(val < 230)
return '9';
if(val < 280)
return '2';
if(val < 330)
return '5';
if(val < 360)
return '#';
if(val < 450)
return '8';
if(val < 525)
return '1';
if(val < 575)
return '0';
if(val < 650)
return '4';
if(val < 750)
return '7';
return '*';
}