Commit 174eab47a410b34ba94cd3e9a100d7438d706430
1 parent
15dd439a
keygraber
Showing
1 changed file
with
51 additions
and
53 deletions
Show diff stats
keygrbb.ino
... | ... | @@ -125,40 +125,38 @@ void setup() { |
125 | 125 | void loop() { |
126 | 126 | // Get the currently touched pads |
127 | 127 | currtouched = cap.touched(); |
128 | - written=false; | |
129 | - | |
128 | + if(currtouched!=lasttouched){ | |
129 | + written=false; | |
130 | 130 | |
131 | 131 | |
132 | 132 | |
133 | 133 | |
134 | - //effacement de la mémoire | |
135 | - if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) { | |
136 | - Serial.println("D"); | |
137 | - fichier.close(); | |
138 | - SD.remove(filename); | |
139 | - fichier=SD.open(filename,FILE_WRITE); | |
140 | - | |
141 | - fichier2.close(); | |
142 | - SD.remove(filename2); | |
143 | - fichier=SD.open(filename2,FILE_WRITE); | |
134 | + //effacement de la mémoire | |
135 | + if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) { | |
136 | + Serial.println("D"); | |
137 | + fichier.close(); | |
138 | + SD.remove(filename); | |
139 | + fichier=SD.open(filename,FILE_WRITE); | |
144 | 140 | |
145 | - //effacer ce qui est présent dans la carte SD | |
146 | - } | |
147 | - //récupération des entrées | |
148 | - if ((currtouched & _BV(5)) && !(lasttouched & _BV(5))) { | |
149 | - Serial.println("R"); | |
150 | - fichier.seek(0); | |
151 | - while((c=fichier.read())!=-1){ | |
152 | - Keyboard.write(c); | |
141 | + fichier2.close(); | |
142 | + SD.remove(filename2); | |
143 | + fichier=SD.open(filename2,FILE_WRITE); | |
153 | 144 | } |
154 | - Keyboard.write(KEY_RETURN); | |
155 | - Keyboard.write(KEY_RETURN); | |
145 | + //récupération des entrées | |
146 | + if ((currtouched & _BV(5)) && !(lasttouched & _BV(5))) { | |
147 | + Serial.println("R"); | |
148 | + fichier.seek(0); | |
149 | + while((c=fichier.read())!=-1){ | |
150 | + Keyboard.write(c); | |
151 | + } | |
152 | + Keyboard.write(KEY_RETURN); | |
153 | + Keyboard.write(KEY_RETURN); | |
156 | 154 | |
157 | - fichier2.seek(0); | |
158 | - while((c=fichier2.read())!=-1){ | |
159 | - Keyboard.write(c); | |
155 | + fichier2.seek(0); | |
156 | + while((c=fichier2.read())!=-1){ | |
157 | + Keyboard.write(c); | |
158 | + } | |
160 | 159 | } |
161 | - } | |
162 | 160 | |
163 | 161 | |
164 | 162 | |
... | ... | @@ -172,37 +170,37 @@ void loop() { |
172 | 170 | |
173 | 171 | |
174 | 172 | |
175 | - for (uint8_t i=0; i<12; i++) { | |
173 | + for (uint8_t i=0; i<12; i++) { | |
176 | 174 | |
177 | - if(i==2 || i==5)i++;//ne pas traiter R et D | |
175 | + if(i==2 || i==5)i++;//ne pas traiter R et D | |
178 | 176 | |
179 | - // it if *is* touched and *wasnt* touched before, alert! | |
180 | - if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { | |
181 | - written=true; | |
182 | - Serial.print(tab[i]); Serial.println(" touched"); | |
183 | - c=('0'+tab[i]); | |
184 | - fichier2.write('<'); | |
185 | - fichier2.write(c); | |
186 | - fichier2.write('>'); | |
187 | - Keyboard.press(c); | |
188 | - } | |
177 | + // it if *is* touched and *wasnt* touched before, alert! | |
178 | + if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { | |
179 | + Serial.print(tab[i]); Serial.println(" touched"); | |
180 | + c=('0'+tab[i]); | |
181 | + fichier2.write('<'); | |
182 | + fichier2.write(c); | |
183 | + fichier2.write('>'); | |
184 | + Keyboard.press(c); | |
185 | + } | |
189 | 186 | |
190 | - // if it *was* touched and now *isnt*, alert! | |
191 | - if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { | |
192 | - written=true; | |
193 | - Serial.print(tab[i]); Serial.println(" released"); | |
194 | - c=('0'+tab[i]); | |
195 | - fichier2.write('>'); | |
196 | - fichier2.write(c); | |
197 | - fichier2.write('<'); | |
187 | + // if it *was* touched and now *isnt*, alert! | |
188 | + if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { | |
189 | + written=true; | |
190 | + Serial.print(tab[i]); Serial.println(" released"); | |
191 | + c=('0'+tab[i]); | |
192 | + fichier2.write('>'); | |
193 | + fichier2.write(c); | |
194 | + fichier2.write('<'); | |
198 | 195 | |
199 | - fichier.write(c); | |
200 | - Keyboard.release(c); | |
196 | + fichier.write(c); | |
197 | + Keyboard.release(c); | |
198 | + } | |
199 | + } | |
200 | + if(written){ | |
201 | + fichier.write('\n'); | |
202 | + fichier.flush();//force l'enregistrement physique des données | |
201 | 203 | } |
202 | - } | |
203 | - if(written){ | |
204 | - fichier.write('\n'); | |
205 | - fichier.flush();//force l'enregistrement physique des données | |
206 | 204 | fichier2.write('\n'); |
207 | 205 | fichier2.flush(); |
208 | 206 | } |
... | ... | @@ -254,4 +252,4 @@ void loop() { |
254 | 252 | |
255 | 253 | |
256 | 254 | // v released >v< |
257 | -// v pressed <v> | |
258 | 255 | \ No newline at end of file |
256 | +// v pressed <v> | ... | ... |