A simple touch sensor that sends a message to computer when it notices touch. I'm using a simple voltage divider with 10k resistor and body impedance.

Dependencies:   mbed

Revision:
3:71bc9b90ff65
Parent:
2:30d2ced09088
Child:
4:9afa1927a7bb
--- a/main.cpp	Thu Jan 30 06:24:52 2014 +0000
+++ b/main.cpp	Thu Feb 06 07:25:45 2014 +0000
@@ -5,71 +5,36 @@
 #define A_key (0x1c)
 
 DigitalOut led(LED1);
-
 DigitalIn  key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30};       //inputit
 int input = 0;
-int i,j,k;
-
-Serial pc(USBTX, USBRX);
+int painetut_nappaimet[9] = {0};
 
-USBMIDI midi;
- 
-int main() {
-    while (1){
-        
-       /* for (i=0; i<9; i++) {            
-            input = key[i].read();
-        }
-        
-        switch (input) {
-            case 0:
-                    pc.printf("Note 0 ON\n\r");
-                    wait(0.25);
-                    pc.printf("Note 0 OFF\n\r");
-                    wait(0.25);
-                
-            case 1:
-                input = key[1].read();
-                
-                    pc.printf("Note 1 ON\n\r");
-                    wait(0.25);
-                    pc.printf("Note 1 OFF\n\r");
-                    wait(0.25);     
-        } */
 
-    
-        for (i=0; i<9; i++) {
-            input = key[i].read();
-            if (!input) {                                     //MIDIT
-                midi.write(MIDIMessage::NoteOn(48+i));
-                //wait(0.25);
-                for(j=0; j<9; j++) {
-                    input = key[j].read();
-                    if (!input) {
-                        midi.write(MIDIMessage::NoteOn(48+j));
-                        //wait(0.25);
-                        for(k=0; k<9; k++) {
-                            input = key[k].read();
-                            if (!input) {
-                                midi.write(MIDIMessage::NoteOn(48+k));
-                                //wait(0.25);
-                            }
-                        }
-                    }
+Serial pc(USBTX, USBRX); //Debuggaus päällä
+//USBMIDI midi; // Midi päällä
+ 
+int main()
+{
+    while (1) 
+    {
+        
+                // Tallentaa painallukset
+                for (i = 0; i < 9; i++) {
+                    if (input = key[i].read())
+                        painetut_nappaimet[i] = 1;
                 }
-            }
-            midi.write(MIDIMessage::NoteOff(48+i));
-            midi.write(MIDIMessage::NoteOff(48+j));
-            midi.write(MIDIMessage::NoteOff(48+k));
-            
-            wait(0.25);
-            
-        } 
-            /* pc.printf("Digital input %d", i);               //terminal viesti
-            pc.printf(": %d\n\r", key[i].read());*/
-        
-
-        /* pc.printf("\n\r");
-        wait(1); */
-    }
-}
\ No newline at end of file
+                // Lähettään painallusten perusteella midimessagen
+                for (i = 0; i < 9; i++) {
+                    if (painetut_nappaimet[i])
+                        //midi.write(MIDIMessage::Noteon(48 + i));
+                        // Debuggaus puttyyn
+                        pc.printf("Digital input %d", i);               //terminal viesti
+                        pc.printf(": %d\n\r", key[i].read());    
+                }
+                // Lopettaa midimessagen lähettämisen
+                for (i = 0; i < 9; i++) {
+                    if (painetut_nappaimet[i])
+                        wait(1);//midi.write(MIDIMessage::NoteOff(48 + i));
+                }
+    } 
+}