2
2
#include < SPI.h>
3
3
#include < SD.h>
4
4
unsigned int d=500 ;
5
- const int c=31 ;
6
- String key[c]={" ENTER" ," CTRL" ," SHIFT" ," ALT" ," GUI" ," UP" ," DOWN" ," LEFT" ," RIGHT" ," PAGEUP" ," PAGEDOWN" ," CAPSLOCK" ," DELETE" ," HOME" ," ESC" ," INSERT" ," TAB" ," END" ," BACKSPACE" ," F1" ," F2" ," F3" ," F4" ," F5" ," F6" ," F7" ," F8" ," F9" ," F10" ," F11" ," F12" };
7
- uint8_t val[c]={0xB0 ,0x80 ,0x81 ,0x82 ,0x83 ,0xDA ,0xD9 ,0xD8 ,0xD7 ,0xD3 ,0xD6 ,0xC1 ,0xD4 ,0xD2 ,0xB1 ,0xD1 ,0xB3 ,0xD5 ,0xB2 ,0xC2 ,0xC3 ,0xC4 ,0xC5 ,0xC6 ,0xC7 ,0xC8 ,0xC9 ,0xCA ,0xCB ,0xCC ,0xCD };
8
- void setup () {
9
- String dip = " " ;
10
- for (;dip.length ()<8 ;dip+=!digitalRead (dip.length ()+2 ))pinMode (dip.length () + 2 , INPUT_PULLUP);
11
- if (!SD.begin (10 ))return ;
12
- File file = SD.open (dip + " .txt" );
13
- if (file) {
5
+ String key[31 ]={" ENTER" ," CTRL" ," SHIFT" ," ALT" ," GUI" ," UP" ," DOWN" ," LEFT" ," RIGHT" ," PAGEUP" ," PAGEDOWN" ," CAPSLOCK" ," DELETE" ," HOME" ," ESC" ," INSERT" ," TAB" ," END" ," BACKSPACE" ," F1" ," F2" ," F3" ," F4" ," F5" ," F6" ," F7" ," F8" ," F9" ," F10" ," F11" ," F12" };
6
+ uint8_t val[31 ]={0xB0 ,0x80 ,0x81 ,0x82 ,0x83 ,0xDA ,0xD9 ,0xD8 ,0xD7 ,0xD3 ,0xD6 ,0xC1 ,0xD4 ,0xD2 ,0xB1 ,0xD1 ,0xB3 ,0xD5 ,0xB2 ,0xC2 ,0xC3 ,0xC4 ,0xC5 ,0xC6 ,0xC7 ,0xC8 ,0xC9 ,0xCA ,0xCB ,0xCC ,0xCD };
7
+ void setup (){
8
+ String dip =" " ;
9
+ for (;dip.length ()<8 ;dip+=!digitalRead (dip.length ()+2 ))pinMode (dip.length ()+2 ,INPUT_PULLUP);
10
+ if (!SD.begin (10 ))return ;
11
+ File file=SD.open (dip+" .txt" );
12
+ if (file){
14
13
Keyboard.begin ();
15
14
delay (500 );
16
- String line = " " ;
17
- while (file.available ()) {
18
- char m = file.read ();
19
- if (m == 10 ) {
15
+ String line= " " ;
16
+ while (file.available ()){
17
+ char m= file.read ();
18
+ if (m== 10 ){
20
19
Line (line);
21
- line = " " ;
20
+ line= " " ;
22
21
}
23
- else if ((int )m != 13 )line += m;
22
+ else if ((int )m!= 13 )line+= m;
24
23
}
25
24
Line (line);
26
25
file.close ();
@@ -29,39 +28,39 @@ void setup() {
29
28
}
30
29
}
31
30
void Line (String l) {
32
- int sp = l.indexOf (" " );
33
- if (sp == -1 )Press (l);
34
- else if (l.substring (0 , sp) == " STRING" )Keyboard.print (l.substring (sp + 1 ));
35
- else if (l.substring (0 , sp) == " STRINGLN" )Keyboard.println (l.substring (sp + 1 ));
36
- else if (l.substring (0 , sp) == " DEFAULT_DELAY" )d = l.substring (sp + 1 ).toInt ();
37
- else if (l.substring (0 , sp) == " DELAY" )delay ((l.substring (sp + 1 ) == " " ) ? d : l.substring (sp + 1 ).toInt ());
38
- else if (l.substring (0 , sp) == " REM" );
31
+ int sp= l.indexOf (" " );
32
+ if (sp== -1 )press (l);
33
+ else if (l.substring (0 ,sp)== " STRING" )Keyboard.print (l.substring (sp+ 1 ));
34
+ else if (l.substring (0 ,sp)== " STRINGLN" )Keyboard.println (l.substring (sp+ 1 ));
35
+ else if (l.substring (0 ,sp)== " DEFAULT_DELAY" )d= l.substring (sp+ 1 ).toInt ();
36
+ else if (l.substring (0 ,sp)== " DELAY" )delay ((l.substring (sp+ 1 )== " " )?d: l.substring (sp+ 1 ).toInt ());
37
+ else if (l.substring (0 ,sp)== " REM" );
39
38
else {
40
- String rest = l;
41
- while (rest.length () > 0 ) {
42
- int spx = rest.indexOf (" " );
43
- if (spx == -1 ) {
44
- Press (rest);
45
- rest = " " ;
46
- } else {
47
- Press (rest.substring (0 , spx));
48
- rest = rest.substring (spx + 1 );
39
+ String rest= l;
40
+ while (rest.length ()> 0 ) {
41
+ int spx= rest.indexOf (" " );
42
+ if (spx== -1 ) {
43
+ press (rest);
44
+ rest= " " ;
45
+ }else {
46
+ press (rest.substring (0 ,spx));
47
+ rest= rest.substring (spx+ 1 );
49
48
}
50
49
delay (500 );
51
50
}
52
51
}
53
52
Keyboard.releaseAll ();
54
53
}
55
- void Press (String b) {
54
+ void press (String b) {
56
55
if (b.length ()==1 )Keyboard.press (b[0 ]);
57
- else if (b.startsWith (" BLK" )){
56
+ else if (b.startsWith (" BLK" )){
58
57
Keyboard.press (0x80 );
59
58
Keyboard.press (0x81 );
60
59
if (b.endsWith (" 100" ))Keyboard.print (" u2588" );
61
60
else if (b.endsWith (" 75" ))Keyboard.print (" u2593" );
62
61
else if (b.endsWith (" 50" ))Keyboard.print (" u2592" );
63
62
else if (b.endsWith (" 25" ))Keyboard.print (" u2591" );
64
63
Keyboard.releaseAll ();
65
- }else for (int i=0 ;i<c ;i++)if (b.equals (key[i]))Keyboard.press (val[i]);
64
+ }else for (int i=0 ;i<31 ;i++)if (b.equals (key[i]))Keyboard.press (val[i]);
66
65
}
67
66
void loop () {}
0 commit comments