-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsketch.cpp
858 lines (827 loc) · 28.5 KB
/
sketch.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/* Arduino Keyboard Mouse
* Copyright (C) 2017 Mac PC Zone
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
/*
Passthrough keypresses from serial to Keyboard
Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
Protocol:
2 bytes total:
1 byte - press flag
0x0 - next key released
0x1 - next key pressed
1 byte - character pressed
for special chars look at arduino keyboard mapping
*/
#include <SoftwareSerial.h>
#include "HID-Project.h"
#include <SoftPWM.h>
#include <TimerOne.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#if USE_SERVO
#include <Servo.h>
#include <EEPROM.h>
#endif
#include <keysims.h>
#if USE_RF24
#include <SPI.h>
#include <nRF24L01.h>
#include "RF24.h"
#include "xxtea-iot-crypt.h"
#endif
SoftwareSerial mySerial(9, 10); // RX, TX
#include <printf.h>
// flag if the next key is pressed or released
bool press=true;
const int led = LED_BUILTIN_RX; // the pin with a LED
const int keyled = 5; // the pin with a LED
bool noecho = 0, neenable = 1;
#if USE_SERVO
const int servopin1 = 7;
const int servopin2 = 8;
Servo myservoa; // create servo object to control a servo
Servo myservob; // create servo object to control a servo
int servodelay = 200;
int rsdelay = 200;
int powerdelay = 10000; // hold the power button in for 10 seconds
#endif
void blinkLED(void);
void setcursor (uint8_t, uint8_t);
void sendnewline (void);
void trdata (void);
LiquidCrystal_I2C ui(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
char text[6];
int timeout = 0;
int countdown = 10;
int rdpin = 6;
int a;
#include "printit.h"
#if USE_RF24
RF24 radio(18,19); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
//RF24 radio(6,4); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
const byte addresses[][6] = {"1Node","2Node"};
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate.
char data[32], gotChars[32], payload[32];
uint8_t value;
bool alive = 0, status = 0;
#endif
void setup()
{
#if USE_RF24
strcpy(payload, "Master Received OK");
xxtea.setKey F("Crypt Password");
pinMode(rdpin, INPUT_PULLUP);
#endif
TXLED0;
RXLED0;
pinMode(keyled, OUTPUT);
for (a = 1; a <= 4; a++) {
digitalWrite(keyled, !digitalRead(keyled));
delay(400);
}
ui.begin(20,4); // initialize the lcd for 20 chars 4 lines, turn on backlight
mySerial.begin(9600);
ui.clear(); // display
// ui.lcd_mode(1); // dual ht
#if USE_RF24
String plaintext = F("**Radio check!**"); //16 chars == 16 bytes
String result = xxtea.encrypt(plaintext);
printf_begin();
if (digitalRead(rdpin) == 0){
alive = 0;
goto skipradio;
}
value = radio.begin();
printit(F("Setup is: "));
printit(value);
sendnewline();
delay(4000);
ui.clear(); // display
radio.setChannel(105);
// radio.enableAckPayload(); // Allow optional ack payloads
// radio.enableDynamicPayloads(); // Ack payloads are dynamic payloads
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_LOW);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.setDataRate(RF24_250KBPS);
// radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(1,10); // Optionally, increase the delay between retries & # of retries
printit(F("Checking the radio"));
value = radio.getChannel();
setcursor(0, 1);
printit(F("Channel is: "));
printit(value);
delay(3000);
value = radio.getPALevel();
setcursor(0, 2);
printit(F("Power is: "));
printit(value);
delay(3000);
value = radio.getDataRate();
setcursor(0, 3);
printit(F("Rate is: "));
printit(value);
sendnewline();
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
delay(3000);
ui.clear(); // display
radio.startListening(); // Start listening
delay(100);
// radio.writeAckPayload(1,&payload,32); // Pre-load an ack-paylod into the FIFO buffer for pipe 1
printit(F("Encrypted length:"));
printit(result.length());
setcursor(0, 1);
printit(F("Encrypted data:"));
setcursor(0, 2);
printit(result);
sendnewline();
delay(2000);
ui.clear();
// strncpy(data, plaintext.c_str(), 32);
strncpy(data, "Turn it on", 32);
trdata();
// printit(F("Sending data"));
// status = radio.write(&data,32);
//// radio.txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail.
// setcursor(0, 1);
// printit(F("Sent data maybe"));
// setcursor(0, 2);
// if ( status ){ // Send the counter variable to the other radio
// radio.startListening(); // Start listening
// unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
// boolean timeout = false; // Set up a variable to indicate if a response was received or not
//
// while ( ! radio.available() ){ // While nothing is received
// if (micros() - started_waiting_at > 20000000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
// timeout = true;
// break;
// }
// }
//
// if ( timeout ){ // Describe the results
// printit(F("Failed, response timed out."));
// }else{
// // Grab the response, compare, and send to debugging spew
// radio.read( &gotChars, 32 ); // Read it, and display the response time
//
// printit(F("Got response: "));
// setcursor(0, 3);
// printit(gotChars);
// alive = 1;
// }
//
// }else{ printit(F("Sending failed.")); } // If no ack response, sending failed
sendnewline();
radio.printDetails();
skipradio:
#endif
sendnewline();
delay(3000); // Try again later
ui.clear();
printit(F("Press a key to begin"));
setcursor(0, 1);
printit(F("or wait ten seconds"));
setcursor(0, 2);
while(mySerial.available() <= 0 && timeout < 100) {
delay(100);
if (timeout % 10 == 0) {
printit(countdown);
printit(F(":"));
countdown--;
if (countdown == 1) {
setcursor(0, 3);
}
}
timeout++;
}
while(mySerial.available()) {
mySerial.read();
delay(200);
}
ui.clear(); // display
sendnewline();
printit(F("System ready!!"));
sendnewline();
delay(1000);
Timer1.initialize(1500000);
Timer1.attachInterrupt(blinkLED); // blinkLED to run every 0.15 seconds
BootKeyboard.begin();
//Serial.begin(9600);
// Initialize
SoftPWMBegin();
// Create and set pin 13 to 0 (off)
SoftPWMSet(led, 0);
// Set fade time for pin 13 to 100 ms fade-up time, and 500 ms fade-down time
SoftPWMSetFadeTime(led, 600, 600);
#if USE_SERVO
myservoa.attach(servopin1); // attaches the servo on pin 9 to the servo object
myservob.attach(servopin2);
myservoa.write(0); // tell servo to go to position in variable 'pos'
myservob.write(0);
delay(1000);
myservoa.detach(); // attaches the servo on pin 9 to the servo object
myservob.detach(); // attaches the servo on pin 9 to the servo object
#endif
}
int ledState = LOW;
int remember1 = 0;
int remember2 = 0;
int remember3 = 0;
int remember4 = 0;
int remember5 = 0;
int remember6 = 0;
int remember7 = 0;
int remember8 = 0;
int remember9 = 0;
int remember10 = 0;
int remember11 = 0;
int remember12 = 0;
int sendit = 0;
int gomouse = 0;
int gokeyboard = 0;
int goservo = 0;
int servoadj = 0;
int mouse = 0;
int blank = 0;
int reset = 0;
int poweroff = 0;
int poweron = 0;
int rservo = 0;
int pservo = 0;
int rightshift = 0;
int mousemove = 40;
int mousebiginc = 100;
int mousesmallinc = 5;
int mousemext;
int togglepower = 0;
int blstate = 1;
void setcursor(uint8_t col, uint8_t row)
{
ui.setCursor(col, row);
if (noecho == 0) {
mySerial.println();
}
}
void sendnewline(void)
{
if (noecho == 0) {
mySerial.println();
}
}
void blinkLED(void)
{
if (ledState == LOW) {
ledState = HIGH;
// Turn on - set to 100%
SoftPWMSetPercent(led, 100);
} else {
ledState = LOW;
// Turn off - set to 0%
SoftPWMSetPercent(led, 0);
// Wait for LED to turn off
}
}
void trdata (void)
{
radio.stopListening(); // First, stop listening so we can talk.
printit(F("Sending data"));
status = radio.write(&data,32);
// radio.txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail.
setcursor(0, 1);
printit(F("Sent data maybe"));
setcursor(0, 2);
if ( status ){ // Send the counter variable to the other radio
radio.startListening(); // Start listening
unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
boolean timeout = false; // Set up a variable to indicate if a response was received or not
while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 20000000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}
if ( timeout ){ // Describe the results
printit(F("Failed, response timed out."));
}else{
// Grab the response, compare, and send to debugging spew
radio.read( &gotChars, 32 ); // Read it, and display the response time
printit(F("Got response: "));
setcursor(0, 3);
printit(gotChars);
alive = 1;
}
}else{ printit(F("Sending failed.")); } // If no ack response, sending failed
}
void downcheck(byte k)
{
if (k == 128) {
remember1 = 1;
}
if (k == 130) {
remember2 = 1;
}
if (k == 50) {
remember3 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember3 == 1) {
sendit = 1;
}
#ifdef USE_MOUSE
if (k == 129) {
remember4 = 1;
}
if (k == 217) {
remember5 = 1;
}
if (remember1 == 1 && remember4 == 1 && remember5 == 1) {
gokeyboard = 1;
}
if (k == 218) {
remember6 = 1;
}
if (remember1 == 1 && remember4 == 1 && remember6 == 1) {
gomouse = 1;
}
#endif // USE_MOUSE
#if USE_SERVO
if (k == 52) {
remember7 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember7 == 1) {
goservo = 1;
}
if (k == 53) {
remember8 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember8 == 1) {
gokeyboard = 1;
}
if (k == 55) {
remember9 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember9 == 1) {
reset = 1;
}
if (k == 56) {
remember10 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember10 == 1) {
poweroff = 1;
}
if (k == 57) {
remember11 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember11 == 1) {
poweron = 1;
}
if (k == 133) {
rightshift = 1;
}
#endif
#if USE_RF24
if (k == 54) {
remember12 = 1;
}
if (remember1 == 1 && remember2 == 1 && remember12 == 1) {
togglepower = 1;
}
#endif // USE_MOUSE
}
void upcheck(byte k)
{
if (k == 128) {
remember1 = 0;
}
if (k == 130) {
remember2 = 0;
}
if (k == 50) {
remember3 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember3 == 0 && sendit == 1) {
sendit = 0;
if (blstate == 0) {
ui.setBacklight(255);
blstate = 1;
}
BootKeyboard.press(KEY_LEFT_CTRL);
delay(100);
BootKeyboard.press(KEY_LEFT_ALT);
delay(100);
BootKeyboard.press(KEY_DELETE);
delay(100);
BootKeyboard.releaseAll();
ui.clear(); // display
// ui.lcd_mode(0); // dual ht
printit(F("Sent"));
setcursor(0, 1);
printit(F("CTRL+ALT+DELETE"));
sendnewline();
RXLED0;
for (a = 1; a <= 8; a++) {
digitalWrite(keyled, !digitalRead(keyled));
delay(400);
}
return;
}
#if USE_MOUSE
if (k == 129) {
remember4 = 0;
}
if (k == 217) {
remember5 = 0;
}
if (remember1 == 0 && remember4 == 0 && remember5 == 0 && gokeyboard == 1) {
gokeyboard = 0;
Mouse.end();
BootKeyboard.begin();
ui.clear(); // display
printit(F("Keyboard mode"));
setcursor(0, 2);
printit(F("enabled"));
sendnewline();
mouse = 0;
return;
}
if (k == 218) {
remember6 = 0;
}
if (remember1 == 0 && remember4 == 0 && remember6 == 0 && gomouse == 1) {
gomouse = 0;
BootKeyboard.end();
Mouse.begin();
ui.clear(); // display
printit(F("Mouse mode"));
setcursor(0, 2);
printit(F("enabled"));
sendnewline();
mouse = 1;
return;
}
#endif // USE_MOUSE
#if USE_SERVO
if (k == 52) {
remember7 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember7 == 0 && goservo == 1) {
goservo = 0;
mouse = 0;
servoadj = 1;
ui.clear(); // display
//ui.lcd_mode(0); // dual ht
printit(F("Servo adjust mode"));
setcursor(0, 1);
printit(F("enabled. Press arrow"));
setcursor(0, 2);
printit(F("keys to move and"));
setcursor(0, 3);
printit(F("Space bar to set."));
sendnewline();
return;
}
if (k == 53) {
remember8 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember8 == 0 && gokeyboard == 1) {
gokeyboard = 0;
mouse = 0;
servoadj = 0;
ui.clear(); // display
//ui.lcd_mode(0); // dual ht
printit(F("Servo adjust mode"));
setcursor(0, 1);
printit(F("disabled."));
sendnewline();
myservoa.attach(servopin1); // attaches the servo on pin 9 to the servo object
myservob.attach(servopin2);
myservoa.write(0); // tell servo to go to position in variable 'pos'
myservob.write(0); // tell servo to go to position in variable 'pos'
delay(1000);
myservoa.detach(); // attaches the servo on pin 9 to the servo object
myservob.detach(); // attaches the servo on pin 9 to the servo object
return;
}
if (k == 55) {
remember9 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember9 == 0 && reset == 1) {
reset = 0;
ui.clear(); // display
printit(F("Resetting the"));
setcursor(0, 1);
printit(F("computer now!!"));
sendnewline();
myservoa.attach(7); // attaches the servo on pin 9 to the servo object
myservoa.write(EEPROM.read(0)); // tell servo to go to position in variable 'pos'
delay(1500);
myservoa.write(0); // tell servo to go to position in variable 'pos'
delay(1000);
myservoa.detach(); // attaches the servo on pin 9 to the servo object
return;
}
if (k == 56) {
remember10 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember10 == 0 && poweroff == 1) {
poweroff = 0;
ui.clear(); // display
printit(F("Powering off the"));
setcursor(0, 1);
printit(F("computer now!!"));
sendnewline();
myservob.attach(servopin2); // attaches the servo on pin 9 to the servo object
myservob.write(EEPROM.read(1)); // tell servo to go to position in variable 'pos'
delay(powerdelay);
myservob.write(0); // tell servo to go to position in variable 'pos'
delay(1000);
myservob.detach(); // attaches the servo on pin 9 to the servo object
return;
}
if (k == 57) {
remember11 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember11 == 0 && poweron == 1) {
poweron = 0;
ui.clear(); // display
printit(F("Powering on the"));
setcursor(0, 1);
printit(F("computer now."));
sendnewline();
myservob.attach(servopin2); // attaches the servo on pin 9 to the servo object
myservob.write(EEPROM.read(1)); // tell servo to go to position in variable 'pos'
delay(2000);
myservob.write(0); // tell servo to go to position in variable 'pos'
delay(1000);
myservob.detach(); // attaches the servo on pin 9 to the servo object
return;
}
if (k == 133) {
rightshift = 0;
}
#endif
#if USE_RF24
if (k == 54) {
remember12 = 0;
}
if (remember1 == 0 && remember2 == 0 && remember12 == 0 && togglepower == 1) {
togglepower = 0;
if (blstate == 0) {
ui.setBacklight(255);
blstate = 1;
}
ui.clear(); // display
if (alive == 1) {
strncpy(data, "Toggle the power relay!!", 32);
trdata();
// radio.stopListening(); // First, stop listening so we can talk.
// printit(F("Starting data send"));
// status = radio.write(&data,32);
//// radio.txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail.
// setcursor(0, 1);
// printit(F("Sent data maybe"));
// setcursor(0, 2);
// if ( status ){ // Send the counter variable to the other radio
// radio.startListening(); // Start listening
// unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
// boolean timeout = false; // Set up a variable to indicate if a response was received or not
//
// while ( ! radio.available() ){ // While nothing is received
// if (micros() - started_waiting_at > 20000000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
// timeout = true;
// break;
// }
// }
//
// if ( timeout ){ // Describe the results
// printit(F("Failed, response timed out."));
// }else{
// // Grab the response, compare, and send to debugging spew
// radio.read( &gotChars, 32 ); // Read it, and display the response time
//
// printit(F("Got response: "));
// setcursor(0, 3);
// printit(gotChars);
// }
//
// }else{ printit(F("Sending failed.")); } // If no ack response, sending failed
}else{
printit(F("No radio link."));
}
}
sendnewline();
#endif
}
void printkey (void)
{
// ui.lcd_mode(1); // dual ht
ui.clear(); // display
printit(F("A: Key: "));
}
void loop()
{
if (mySerial.available()) {
byte k = mySerial.read();
itoa(k, text, 10);
if (neenable == 0) {
mySerial.print(F("A:: "));
mySerial.print(text);
mySerial.println(F(" received"));
}
if (k == 0) {
press = 0;
} else if (k == 1) {
press = 1;
} else {
//mySerial.write(k);
if (press) {
if (mouse == 0 && servoadj == 0) {
if (neenable == 1) {
if (blstate == 1) {
ui.setBacklight(0);
blstate =0;
}
noecho = 1;
}
printkey();
itoa(k, text, 10);
printit(String(text) + String(F(" Pressed")));
sendnewline();
BootKeyboard.press((KeyboardKeycode)pgm_read_byte(&keysims[k]));
if (neenable == 1) {
noecho = 0;
}
//mySerial.println(" pressed");
} else if (servoadj == 1) {
#if USE_SERVO
if (neenable == 1) {
noecho = 1;
}
switch (k) {
case 218:
// move mouse up
if (rservo < 170) {
rservo = rservo + rightshift * 9 + 1;
}
myservoa.attach(servopin1); // attaches the servo on pin 9 to the servo object
myservoa.write(rservo); // tell servo to go to position in variable 'pos'
delay(servodelay + rightshift * rsdelay);
myservoa.detach(); // attaches the servo on pin 9 to the servo object
ui.clear(); // display
printit(F("Servo reset in."));
setcursor(0, 1);
printit(F("Servo pos is: "));
printit(rservo);
sendnewline();
break;
case 217:
// move mouse down
if (rservo > 10) {
rservo = rservo - rightshift * 9 - 1;
}
myservoa.attach(servopin1); // attaches the servo on pin 9 to the servo object
myservoa.write(rservo); // tell servo to go to position in variable 'pos'
delay(servodelay + rightshift * rsdelay);
myservoa.detach(); // attaches the servo on pin 9 to the servo object
ui.clear(); // display
printit(F("Servo reset out"));
setcursor(0, 1);
printit(F("Servo pos is: "));
printit(rservo);
sendnewline();
break;
case 216:
// move mouse left
if (pservo < 170) {
pservo = pservo + rightshift * 9 + 1;
}
myservob.attach(servopin2); // attaches the servo on pin 9 to the servo object
myservob.write(pservo); // tell servo to go to position in variable 'pos'
delay(servodelay + rightshift * rsdelay);
myservob.detach(); // attaches the servo on pin 9 to the servo object
ui.clear(); // display
printit(F("Servo power in"));
setcursor(0, 1);
printit(F("Servo pos is: "));
printit(pservo);
sendnewline();
break;
case 215:
// move mouse right
if (pservo > 10) {
pservo = pservo - rightshift * 9 - 1;
}
myservob.attach(servopin2); // attaches the servo on pin 9 to the servo object
myservob.write(pservo); // tell servo to go to position in variable 'pos'
delay(servodelay + rightshift * rsdelay);
myservob.detach(); // attaches the servo on pin 9 to the servo object
ui.clear(); // display
printit(F("Servo power out"));
setcursor(0, 1);
printit(F("Servo pos is: "));
printit(pservo);
sendnewline();
break;
case 32:
// perform mouse left click
EEPROM.update(0, rservo);
EEPROM.update(1, pservo);
ui.clear(); // display
printit(F("Positions saved"));
setcursor(0, 1);
printit(F("to EEPROM"));
sendnewline();
break;
}
if (neenable == 1) {
noecho = 0;
}
#endif
} else {
#if USE_MOUSE
if (neenable == 1) {
noecho = 1;
}
mousemext = remember1 * (mousebiginc - mousemove) - remember4 * (mousemove - mousesmallinc);
ui.clear(); // display
switch (k) {
case 218:
// move mouse up
Mouse.move(0, -40 - mousemext);
printit(F("Mouse up"));
break;
case 217:
// move mouse down
Mouse.move(0, 40 + mousemext);
printit(F("Mouse down"));
break;
case 216:
// move mouse left
Mouse.move(-40 - mousemext, 0);
printit(F("Mouse left"));
break;
case 215:
// move mouse right
Mouse.move(40 + mousemext, 0);
printit(F("Mouse right"));
break;
case 32:
// perform mouse left click
Mouse.click(MOUSE_LEFT);
printit(F("Click left"));
break;
case 134:
// perform mouse right click
Mouse.click(MOUSE_RIGHT);
printit(F("Click right"));
break;
}
sendnewline();
if (neenable == 1) {
noecho = 0;
}
#endif // USE_MOUSE
}
downcheck(k);
} else {
if (mouse == 0 && servoadj == 0) {
if (neenable == 1) {
noecho = 1;
}
printkey();
itoa(k, text, 10);
printit(String(text) + String(F(" Released")));
sendnewline();
BootKeyboard.release((KeyboardKeycode)pgm_read_byte(&keysims[k]));
if (neenable == 1) {
noecho = 0;
}
} else {
}
upcheck(k);
}
//mySerial.println(" released");
digitalWrite(keyled, 1);
delay(40);
digitalWrite(keyled, 0);
}
}
// Wait for LED to turn on - you could do other tasks here
}