SHOW:
|
|
- or go back to the newest paste.
1 | // include the library code: | |
2 | #include <LiquidCrystal.h> | |
3 | - | int byteincome = 0; |
3 | + | int byteincome = 0; |
4 | // initialize the library with the numbers of the interface pins | |
5 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
6 | //Key message | |
7 | int adc_key_val[5] = { | |
8 | - | int adc_key_val[5] ={30, 150, 360, 535, 760 }; |
8 | + | 30, 150, 360, 535, 760 |
9 | - | String statuses[] = {"Coding", "Doing Homework", "Please Leave", "Away", "Sleeping", "Calling Home", "Gaming", "GET OUT"}; |
9 | + | }; |
10 | - | String top[] = {'Status:', 'Adam:', 'Oliver:', 'Adam & Oliver:', 'Awesomeness'. 'OBEY:'}; |
10 | + | String statuses[] = { |
11 | "Coding", "Doing Homework", "Please Leave", "Away", "Sleeping", "Calling Home", "Gaming", "GET OUT" | |
12 | }; | |
13 | - | int key=-1; |
13 | + | String top[] = { |
14 | - | int oldkey=-1; |
14 | + | "Status:", "Adam:", "Oliver:", "Adam & Oliver:", "Awesomeness", "OBEY:" |
15 | }; | |
16 | int NUM_KEYS = 5; | |
17 | int adc_key_in; | |
18 | int key = -1; | |
19 | int oldkey = -1; | |
20 | - | // set up the LCD's number of columns and rows: |
20 | + | |
21 | - | lcd.begin(16, 2); |
21 | + | |
22 | - | lcd.setCursor(0, 1); |
22 | + | |
23 | - | intro(); |
23 | + | |
24 | - | Serial.begin(9600); |
24 | + | |
25 | - | pinMode(10, OUTPUT); |
25 | + | |
26 | - | digitalWrite(blp, HIGH); |
26 | + | // set up the LCD's number of columns and rows: |
27 | lcd.begin(16, 2); | |
28 | lcd.setCursor(0, 1); | |
29 | intro(); | |
30 | Serial.begin(9600); | |
31 | pinMode(10, OUTPUT); | |
32 | - | // set the cursor to column 0, line 1 |
32 | + | digitalWrite(blp, HIGH); |
33 | - | // (note: line 1 is the second row, since counting begins with 0): |
33 | + | |
34 | ||
35 | void loop() { | |
36 | - | adc_key_in = analogRead(0); // read the value from the sensor |
36 | + | // set the cursor to column 0, line 1 |
37 | // (note: line 1 is the second row, since counting begins with 0): | |
38 | - | key = get_key(adc_key_in); // convert into key press |
38 | + | |
39 | - | if (key != oldkey) // if keypress is detected |
39 | + | adc_key_in = analogRead(0); // read the value from the sensor |
40 | - | { |
40 | + | key = get_key(adc_key_in); // convert into key press |
41 | - | delay(50); // wait for debounce time |
41 | + | if (key != oldkey) // if keypress is detected |
42 | - | adc_key_in = analogRead(0); // read the value from the sensor |
42 | + | |
43 | - | key = get_key(adc_key_in); // convert into key press |
43 | + | delay(50); // wait for debounce time |
44 | - | if (key != oldkey) |
44 | + | adc_key_in = analogRead(0); // read the value from the sensor |
45 | - | { |
45 | + | key = get_key(adc_key_in); // convert into key press |
46 | - | oldkey = key; |
46 | + | if (key != oldkey) { |
47 | oldkey = key; | |
48 | - | if (key==0) |
48 | + | if (key == 0) { |
49 | - | { |
49 | + | j++; |
50 | - | j++; |
50 | + | if (j > 5) { |
51 | - | if (j>5) |
51 | + | j = 0; |
52 | } | |
53 | - | j = 0; |
53 | + | lcd.clear(); |
54 | lcd.setCursor(0, 0); | |
55 | lcd.print(top[j]); | |
56 | lcd.setCursor(0, 1); | |
57 | - | lcd.print(top[j]); |
57 | + | lcd.print(statuses[i]); |
58 | } | |
59 | if (key == 3) { | |
60 | - | lcd.write(statuses[i]); |
60 | + | j--; |
61 | if (j < 0) { | |
62 | j = 5; | |
63 | - | if (key==3) |
63 | + | } |
64 | - | { |
64 | + | lcd.clear(); |
65 | - | j--; |
65 | + | lcd.setCursor(0, 0); |
66 | - | if (j<0) |
66 | + | lcd.print(top[j]); |
67 | lcd.setCursor(0, 1); | |
68 | - | j = 5; |
68 | + | lcd.print(statuses[i]); |
69 | } | |
70 | if (key == 1) //down key | |
71 | { | |
72 | - | lcd.print(top[j]); |
72 | + | i--; |
73 | if (i == -1) { | |
74 | i = 7; | |
75 | - | lcd.write(statuses[i]); |
75 | + | } |
76 | lcd.clear(); | |
77 | lcd.setCursor(0, 0); | |
78 | - | if (key == 1) //down key |
78 | + | lcd.print(top[j]); |
79 | - | { |
79 | + | lcd.setCursor(0, 1); |
80 | - | i--; |
80 | + | lcd.print(statuses[i]); |
81 | - | if (i == -1) |
81 | + | } |
82 | if (key == 2) //up key | |
83 | - | i = 7; |
83 | + | { |
84 | i++; | |
85 | if (i > 7) { | |
86 | i = 0; | |
87 | - | lcd.print(top[j]); |
87 | + | } |
88 | lcd.clear(); | |
89 | - | lcd.print(statuses[i]); |
89 | + | lcd.setCursor(0, 0); |
90 | - | |
90 | + | lcd.print(top[j]); |
91 | lcd.setCursor(0, 1); | |
92 | - | if (key == 2) //up key |
92 | + | lcd.print(statuses[i]); |
93 | - | { |
93 | + | } else if (key == 4) { |
94 | - | i++; |
94 | + | if (mode == 0) { |
95 | - | if (i>7) |
95 | + | mode = 1; |
96 | lcd.noDisplay(); | |
97 | - | i = 0; |
97 | + | digitalWrite(10, LOW); |
98 | } else if (mode == 1) { | |
99 | mode = 2; | |
100 | lcd.display(); | |
101 | - | lcd.print(top[j]); |
101 | + | digitalWrite(10, LOW); |
102 | } else if (mode == 2) { | |
103 | - | lcd.print(statuses[i]); |
103 | + | mode = 0; |
104 | - | |
104 | + | lcd.display(); |
105 | digitalWrite(10, HIGH); | |
106 | - | else if (key == 4) |
106 | + | } |
107 | - | { |
107 | + | } |
108 | - | if (mode == 0) |
108 | + | } |
109 | } | |
110 | - | mode = 1; |
110 | + | |
111 | - | lcd.noDisplay(); |
111 | + | |
112 | - | digitalWrite(10, LOW); |
112 | + | |
113 | int get_key(unsigned int input) { | |
114 | - | else if (mode == 1) |
114 | + | int k; |
115 | for (k = 0; k < NUM_KEYS; k++) { | |
116 | if (input < adc_key_val[k]) { | |
117 | - | mode = 2; |
117 | + | return k; |
118 | - | lcd.display(); |
118 | + | } |
119 | - | digitalWrite(10, LOW); |
119 | + | |
120 | if (k >= NUM_KEYS) | |
121 | k = -1; // No valid key pressed | |
122 | - | else if (mode == 2) |
122 | + | return k; |
123 | ||
124 | - | mode = 0; |
124 | + | |
125 | - | lcd.display(); |
125 | + | int intro() { |
126 | - | digitalWrite(10, HIGH); |
126 | + | |
127 | lcd.print("Select: Mode"); | |
128 | lcd.setCursor(0, 1); | |
129 | lcd.print("Left/Right: Top"); | |
130 | delay(1500); | |
131 | lcd.clear(); | |
132 | lcd.setCursor(0, 0); | |
133 | lcd.print("Left/Right: Top"); | |
134 | - | int get_key(unsigned int input) |
134 | + | |
135 | - | { int k; |
135 | + | |
136 | - | for (k = 0; k < NUM_KEYS; k++) |
136 | + | |
137 | - | { |
137 | + | |
138 | - | if (input < adc_key_val[k]) |
138 | + | |
139 | - | { return k; } |
139 | + | |
140 | lcd.setCursor(0, 1); | |
141 | - | if (k >= NUM_KEYS) |
141 | + | |
142 | - | k = -1; // No valid key pressed |
142 | + | |
143 | - | return k; |
143 | + | |
144 | lcd.setCursor(0, 0); | |
145 | lcd.print("Status:"); | |
146 | - | } |
146 | + | |
147 | - | int intro() |
147 | + | |
148 | - | { |
148 | + | |
149 | - | lcd.setCursor(0, 0); |
149 | + |