Commit 45bbb2b8962e0dd81cfd8262b267970156e94d48
1 parent
40c27986
setup sd file ok
gestion r et d
Showing
1 changed file
with
45 additions
and
11 deletions
Show diff stats
keygrbb.ino
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | #include <string.h> |
7 | 7 | #define ti 20 |
8 | 8 | |
9 | +#include<SD.h> | |
10 | + | |
9 | 11 | #ifndef _BV |
10 | 12 | #define _BV(bit) (1 << (bit)) |
11 | 13 | #endif |
... | ... | @@ -18,6 +20,9 @@ Adafruit_MPR121 cap = Adafruit_MPR121(); |
18 | 20 | uint16_t lasttouched = 0; |
19 | 21 | uint16_t currtouched = 0; |
20 | 22 | int tab[]={3,7,15,2,6,14,1,5,9,0,4,8}; |
23 | +File fichier; | |
24 | +String filename="texte.txt"; | |
25 | +char c; | |
21 | 26 | |
22 | 27 | |
23 | 28 | void Printstr(String msg){ |
... | ... | @@ -53,10 +58,21 @@ void setup() { |
53 | 58 | |
54 | 59 | //Serial |
55 | 60 | Serial.begin(9600); |
56 | - | |
57 | 61 | while (!Serial) { // needed to keep leonardo/micro from starting too fast! |
58 | 62 | delay(10); |
59 | 63 | } |
64 | + | |
65 | + //SD | |
66 | + while(! SD.begin(4)){ | |
67 | + delay(1000); | |
68 | + } | |
69 | + Serial.println("SD OK"); | |
70 | + | |
71 | + //File | |
72 | + while( !(fichier=SD.open(filename,FILE_WRITE)) ){ | |
73 | + delay(1000); | |
74 | + } | |
75 | + Serial.println("file OK"); | |
60 | 76 | |
61 | 77 | //keyboard in |
62 | 78 | Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); |
... | ... | @@ -74,32 +90,47 @@ void setup() { |
74 | 90 | |
75 | 91 | |
76 | 92 | |
93 | + | |
94 | + | |
95 | + | |
96 | + | |
97 | + | |
98 | + | |
99 | + | |
100 | + | |
101 | + | |
102 | + | |
77 | 103 | void loop() { |
78 | 104 | // Get the currently touched pads |
79 | 105 | currtouched = cap.touched(); |
80 | 106 | /* |
81 | 107 | //effacement de la mémoire |
82 | - if ((currtouched & _BV(/*D*/)) && !(lasttouched & _BV(/*D*/)) ) { | |
108 | + if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) { | |
109 | + Serial.println("D"); | |
83 | 110 | //effacer ce qui est présent dans la carte SD |
84 | - } | |
111 | + }*/ | |
85 | 112 | //récupération des entrées |
86 | - if ((currtouched & _BV(/*R*/)) && !(lasttouched & _BV(/*R*/)) ) { | |
87 | - //gérer la lecture du fichier contenant les entrées | |
88 | - //récupération des entrées | |
89 | - //Keyboard.write(entrée) | |
113 | + if ((currtouched & _BV(5)) && !(lasttouched & _BV(5))) { | |
114 | + Serial.println("R"); | |
115 | + fichier.seek(0); | |
116 | + while((c=fichier.read())!=-1){ | |
117 | + Keyboard.write(c); | |
90 | 118 | } |
91 | - */ | |
119 | + } | |
120 | + | |
92 | 121 | |
93 | 122 | for (uint8_t i=0; i<12; i++) { |
94 | 123 | // it if *is* touched and *wasnt* touched before, alert! |
95 | 124 | if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { |
96 | 125 | Serial.print(tab[i]); Serial.println(" touched"); |
97 | - Keyboard.press('0'+tab[i]); | |
126 | + c=('0'+tab[i]); | |
127 | + Keyboard.press(c); | |
98 | 128 | } |
99 | 129 | // if it *was* touched and now *isnt*, alert! |
100 | 130 | if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { |
101 | 131 | Serial.print(tab[i]); Serial.println(" released"); |
102 | - Keyboard.release('0'+tab[i]); | |
132 | + c=('0'+tab[i]); | |
133 | + Keyboard.release(c); | |
103 | 134 | } |
104 | 135 | if(i==1 || i==5)i++; |
105 | 136 | } |
... | ... | @@ -125,4 +156,7 @@ void loop() { |
125 | 156 | |
126 | 157 | // put a delay so it isn't overwhelming |
127 | 158 | delay(100); |
128 | -} | |
129 | 159 | \ No newline at end of file |
160 | +} | |
161 | + | |
162 | + | |
163 | +// >v< <v> | ... | ... |