1 | #include <Keyboard.h>
|
2 | #include <FastLED.h>
|
3 | #define LED_PIN 9
|
4 | #define NUM_LEDS 10
|
5 | #define BUTTON_KEY1 97
|
6 | #define BUTTON_KEY2 98
|
7 | #define BUTTON_KEY3 99
|
8 | #define BUTTON_KEY4 100
|
9 | #define BUTTON_KEY5 101
|
10 | #define BUTTON_KEY6 102
|
11 | CRGB leds[NUM_LEDS];
|
12 |
|
13 | const int buttonPin1 = 2;
|
14 | const int buttonPin2 = 4;
|
15 | const int buttonPin3 = 5;
|
16 | const int buttonPin4 = 6;
|
17 | const int buttonPin5 = 7;
|
18 | const int buttonPin6 = 8;
|
19 |
|
20 | int merker1 = 0;
|
21 | int merker2 = 0;
|
22 | int merker3 = 0;
|
23 | int merker4 = 0;
|
24 | int merker5 = 0;
|
25 | int merker6 = 0;
|
26 |
|
27 | int buttonState1;
|
28 | int buttonState2;
|
29 | int buttonState3;
|
30 | int buttonState4;
|
31 | int buttonState5;
|
32 | int buttonState6;
|
33 |
|
34 | int lastButtonState1 = LOW;
|
35 | int lastButtonState2 = LOW;
|
36 | int lastButtonState3 = LOW;
|
37 | int lastButtonState4 = LOW;
|
38 | int lastButtonState5 = LOW;
|
39 | int lastButtonState6 = LOW;
|
40 |
|
41 | unsigned long lastDebounceTime1 = 0;
|
42 | unsigned long lastDebounceTime2 = 0;
|
43 | unsigned long lastDebounceTime3 = 0;
|
44 | unsigned long lastDebounceTime4 = 0;
|
45 | unsigned long lastDebounceTime5 = 0;
|
46 | unsigned long lastDebounceTime6 = 0;
|
47 |
|
48 | unsigned long debounceDelay = 50;
|
49 |
|
50 | void setup() {
|
51 |
|
52 | Serial.begin(9600);
|
53 | pinMode(buttonPin1, INPUT);
|
54 | pinMode(buttonPin2, INPUT);
|
55 | pinMode(buttonPin3, INPUT);
|
56 | pinMode(buttonPin4, INPUT);
|
57 | pinMode(buttonPin5, INPUT);
|
58 | pinMode(buttonPin6, INPUT);
|
59 |
|
60 | FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
|
61 | Keyboard.begin();
|
62 | }
|
63 |
|
64 | void loop() {
|
65 |
|
66 | //*********************Taster 1******************************
|
67 |
|
68 | int reading1 = digitalRead(buttonPin1);
|
69 | if (reading1 != lastButtonState1) {
|
70 | lastDebounceTime1 = millis();
|
71 | }
|
72 | if ((millis() - lastDebounceTime1) > debounceDelay) {
|
73 | if (reading1 != buttonState1) {
|
74 | buttonState1 = reading1;
|
75 | int reading = digitalRead(buttonPin1);
|
76 | if ((buttonState1 == HIGH) && (merker1 == 2)) {
|
77 | lastDebounceTime1 = millis();
|
78 | leds[0] = 0x00FF00;
|
79 | FastLED.show();
|
80 | Keyboard.press(BUTTON_KEY1);
|
81 | Keyboard.releaseAll();
|
82 | merker1 = 1;
|
83 | }
|
84 | else if ((buttonState1 == HIGH) && (merker1 == 1))
|
85 | {
|
86 | leds[0] = 0xFF0000;
|
87 | FastLED.show();
|
88 | Keyboard.press(BUTTON_KEY1);
|
89 | Keyboard.releaseAll();
|
90 | merker1 = 0;
|
91 | }
|
92 | }
|
93 | }
|
94 | else if ((buttonState1 == LOW) && (merker1 == 0))
|
95 | {
|
96 | leds[0] = 0xFF0000;
|
97 | FastLED.show();
|
98 | merker1 = 2;
|
99 | }
|
100 | lastButtonState1 = reading1;
|
101 |
|
102 | //*********************Taster 2******************************
|
103 |
|
104 | int reading2 = digitalRead(buttonPin2);
|
105 | if (reading2 != lastButtonState2) {
|
106 | lastDebounceTime2 = millis();
|
107 | }
|
108 | if ((millis() - lastDebounceTime2) > debounceDelay) {
|
109 | if (reading2 != buttonState2) {
|
110 | buttonState2 = reading2;
|
111 | int reading2 = digitalRead(buttonPin2);
|
112 | if ((buttonState2 == HIGH) && (merker2 == 2)) {
|
113 | lastDebounceTime2 = millis();
|
114 | leds[1] = 0x00FF00;
|
115 | FastLED.show();
|
116 | Keyboard.press(BUTTON_KEY2);
|
117 | Keyboard.releaseAll();
|
118 | merker2 = 1;
|
119 | }
|
120 | else if ((buttonState2 == HIGH) && (merker2 == 1))
|
121 | {
|
122 | leds[1] = 0xFF0000;
|
123 | FastLED.show();
|
124 | Keyboard.press(BUTTON_KEY2);
|
125 | Keyboard.releaseAll();
|
126 | merker2 = 0;
|
127 | }
|
128 | }
|
129 | }
|
130 | else if ((buttonState2 == LOW) && (merker2 == 0))
|
131 | {
|
132 | leds[1] = 0xFF0000;
|
133 | FastLED.show();
|
134 | merker2 = 2;
|
135 | }
|
136 | lastButtonState2 = reading2;
|
137 |
|
138 | //*********************Taster 3******************************
|
139 |
|
140 | int reading3 = digitalRead(buttonPin3);
|
141 | if (reading3 != lastButtonState3) {
|
142 | lastDebounceTime3 = millis();
|
143 | }
|
144 | if ((millis() - lastDebounceTime3) > debounceDelay) {
|
145 | if (reading3 != buttonState3) {
|
146 | buttonState3 = reading3;
|
147 | int reading3 = digitalRead(buttonPin3);
|
148 | if ((buttonState3 == HIGH) && (merker3 == 2)) {
|
149 | lastDebounceTime3 = millis();
|
150 | leds[2] = 0x00FF00;
|
151 | FastLED.show();
|
152 | Keyboard.press(BUTTON_KEY3);
|
153 | Keyboard.releaseAll();
|
154 | merker3 = 1;
|
155 | }
|
156 | else if ((buttonState3 == HIGH) && (merker3 == 1))
|
157 | {
|
158 | leds[2] = 0xFF0000;
|
159 | FastLED.show();
|
160 | Keyboard.press(BUTTON_KEY3);
|
161 | Keyboard.releaseAll();
|
162 | merker3 = 0;
|
163 | }
|
164 | }
|
165 | }
|
166 | else if ((buttonState3 == LOW) && (merker3 == 0))
|
167 | {
|
168 | leds[2] = 0xFF0000;
|
169 | FastLED.show();
|
170 | merker3 = 2;
|
171 | }
|
172 | lastButtonState3 = reading3;
|
173 |
|
174 | //*********************Taster 4******************************
|
175 |
|
176 | int reading4 = digitalRead(buttonPin4);
|
177 | if (reading4 != lastButtonState4) {
|
178 | lastDebounceTime4 = millis();
|
179 | }
|
180 | if ((millis() - lastDebounceTime4) > debounceDelay) {
|
181 | if (reading4 != buttonState4) {
|
182 | buttonState4 = reading4;
|
183 | int reading4 = digitalRead(buttonPin4);
|
184 | if ((buttonState4 == HIGH) && (merker4 == 2)) {
|
185 | lastDebounceTime4 = millis();
|
186 | leds[3] = 0x00FF00;
|
187 | FastLED.show();
|
188 | Keyboard.press(BUTTON_KEY4);
|
189 | Keyboard.releaseAll();
|
190 | merker4 = 1;
|
191 | }
|
192 | else if ((buttonState4 == HIGH) && (merker4 == 1))
|
193 | {
|
194 | leds[3] = 0xFF0000;
|
195 | FastLED.show();
|
196 | Keyboard.press(BUTTON_KEY4);
|
197 | Keyboard.releaseAll();
|
198 | merker4 = 0;
|
199 | }
|
200 | }
|
201 | }
|
202 | else if ((buttonState4 == LOW) && (merker4 == 0))
|
203 | {
|
204 | leds[3] = 0xFF0000;
|
205 | FastLED.show();
|
206 | merker4 = 2;
|
207 | }
|
208 | lastButtonState4 = reading4;
|
209 |
|
210 | //*********************Taster 5******************************
|
211 |
|
212 | int reading5 = digitalRead(buttonPin5);
|
213 | if (reading5 != lastButtonState5) {
|
214 | lastDebounceTime5 = millis();
|
215 | }
|
216 | if ((millis() - lastDebounceTime5) > debounceDelay) {
|
217 | if (reading5 != buttonState5) {
|
218 | buttonState5 = reading5;
|
219 | int reading5 = digitalRead(buttonPin5);
|
220 | if ((buttonState5 == HIGH) && (merker5 == 2)) {
|
221 | lastDebounceTime5 = millis();
|
222 | leds[4] = 0x00FF00;
|
223 | FastLED.show();
|
224 | Keyboard.press(BUTTON_KEY5);
|
225 | Keyboard.releaseAll();
|
226 | merker5 = 1;
|
227 | }
|
228 | else if ((buttonState5 == HIGH) && (merker5 == 1))
|
229 | {
|
230 | leds[4] = 0xFF0000;
|
231 | FastLED.show();
|
232 | Keyboard.press(BUTTON_KEY5);
|
233 | Keyboard.releaseAll();
|
234 | merker5 = 0;
|
235 | }
|
236 | }
|
237 | }
|
238 | else if ((buttonState5 == LOW) && (merker5 == 0))
|
239 | {
|
240 | leds[4] = 0xFF0000;
|
241 | FastLED.show();
|
242 | merker5 = 2;
|
243 | }
|
244 | lastButtonState5 = reading5;
|
245 |
|
246 | //*********************Taster 6******************************
|
247 |
|
248 | int reading6 = digitalRead(buttonPin6);
|
249 | if (reading6 != lastButtonState6) {
|
250 | lastDebounceTime6 = millis();
|
251 | }
|
252 | if ((millis() - lastDebounceTime6) > debounceDelay) {
|
253 | if (reading6 != buttonState6) {
|
254 | buttonState6 = reading6;
|
255 | int reading6 = digitalRead(buttonPin6);
|
256 | if ((buttonState6 == HIGH) && (merker6 == 2)) {
|
257 | lastDebounceTime6 = millis();
|
258 | leds[5] = 0x00FF00;
|
259 | FastLED.show();
|
260 | Keyboard.press(BUTTON_KEY6);
|
261 | Keyboard.releaseAll();
|
262 | merker6 = 1;
|
263 | }
|
264 | else if ((buttonState6 == HIGH) && (merker6 == 1))
|
265 | {
|
266 | leds[5] = 0xFF0000;
|
267 | FastLED.show();
|
268 | Keyboard.press(BUTTON_KEY6);
|
269 | Keyboard.releaseAll();
|
270 | merker6 = 0;
|
271 | }
|
272 | }
|
273 | }
|
274 | else if ((buttonState6 == LOW) && (merker6 == 0))
|
275 | {
|
276 | leds[5] = 0xFF0000;
|
277 | FastLED.show();
|
278 | merker6 = 2;
|
279 | }
|
280 | lastButtonState6 = reading6;
|
281 |
|
282 | leds[6] = 0x0000FF;
|
283 | FastLED.show();
|
284 | leds[7] = 0x0000FF;
|
285 | FastLED.show();
|
286 | leds[8] = 0x0000FF;
|
287 | FastLED.show();
|
288 | leds[9] = 0x0000FF;
|
289 | FastLED.show();
|
290 | }
|