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:
1:7ed7d128d225
Parent:
0:9720755e6762
Child:
2:30d2ced09088
--- a/main.cpp	Fri Jan 24 14:32:15 2014 +0000
+++ b/main.cpp	Thu Jan 30 06:13:55 2014 +0000
@@ -1,21 +1,60 @@
 //Almighty Vekotin v.1.0
 
 #include "mbed.h"
- 
-AnalogIn ain(p16);
+#include "USBMIDI.h"
+#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;
+
 Serial pc(USBTX, USBRX);
-float input;
+
+//USBMIDI midi;
  
 int main() {
     while (1){
         
-        input = ain.read();             //reads input in p16
-                                        //without touch input is HIGH (1) 
-        if (input < 1){                 //with touch input changes its value  
-            pc.printf("TOUCH!");         
+       /* for (i=0; i<9; i++) {            
+            input = key[i].read();
         }
         
-        wait(0.25);
-        
+        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);
+                midi.write(MIDIMessage::NoteOff(48+i));
+                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