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.
main.cpp@2:30d2ced09088, 2014-01-30 (annotated)
- Committer:
- tanssisatu
- Date:
- Thu Jan 30 06:24:52 2014 +0000
- Revision:
- 2:30d2ced09088
- Parent:
- 1:7ed7d128d225
- Child:
- 3:71bc9b90ff65
plob multitouch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vekotin | 0:9720755e6762 | 1 | //Almighty Vekotin v.1.0 |
Vekotin | 0:9720755e6762 | 2 | |
Vekotin | 0:9720755e6762 | 3 | #include "mbed.h" |
Vekotin | 1:7ed7d128d225 | 4 | #include "USBMIDI.h" |
Vekotin | 1:7ed7d128d225 | 5 | #define A_key (0x1c) |
Vekotin | 1:7ed7d128d225 | 6 | |
Vekotin | 1:7ed7d128d225 | 7 | DigitalOut led(LED1); |
Vekotin | 1:7ed7d128d225 | 8 | |
Vekotin | 1:7ed7d128d225 | 9 | DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit |
Vekotin | 1:7ed7d128d225 | 10 | int input = 0; |
tanssisatu | 2:30d2ced09088 | 11 | int i,j,k; |
Vekotin | 1:7ed7d128d225 | 12 | |
Vekotin | 0:9720755e6762 | 13 | Serial pc(USBTX, USBRX); |
Vekotin | 1:7ed7d128d225 | 14 | |
tanssisatu | 2:30d2ced09088 | 15 | USBMIDI midi; |
Vekotin | 0:9720755e6762 | 16 | |
Vekotin | 0:9720755e6762 | 17 | int main() { |
Vekotin | 0:9720755e6762 | 18 | while (1){ |
Vekotin | 0:9720755e6762 | 19 | |
Vekotin | 1:7ed7d128d225 | 20 | /* for (i=0; i<9; i++) { |
Vekotin | 1:7ed7d128d225 | 21 | input = key[i].read(); |
Vekotin | 0:9720755e6762 | 22 | } |
Vekotin | 0:9720755e6762 | 23 | |
Vekotin | 1:7ed7d128d225 | 24 | switch (input) { |
Vekotin | 1:7ed7d128d225 | 25 | case 0: |
Vekotin | 1:7ed7d128d225 | 26 | pc.printf("Note 0 ON\n\r"); |
Vekotin | 1:7ed7d128d225 | 27 | wait(0.25); |
Vekotin | 1:7ed7d128d225 | 28 | pc.printf("Note 0 OFF\n\r"); |
Vekotin | 1:7ed7d128d225 | 29 | wait(0.25); |
Vekotin | 1:7ed7d128d225 | 30 | |
Vekotin | 1:7ed7d128d225 | 31 | case 1: |
Vekotin | 1:7ed7d128d225 | 32 | input = key[1].read(); |
Vekotin | 1:7ed7d128d225 | 33 | |
Vekotin | 1:7ed7d128d225 | 34 | pc.printf("Note 1 ON\n\r"); |
Vekotin | 1:7ed7d128d225 | 35 | wait(0.25); |
Vekotin | 1:7ed7d128d225 | 36 | pc.printf("Note 1 OFF\n\r"); |
Vekotin | 1:7ed7d128d225 | 37 | wait(0.25); |
Vekotin | 1:7ed7d128d225 | 38 | } */ |
Vekotin | 1:7ed7d128d225 | 39 | |
Vekotin | 1:7ed7d128d225 | 40 | |
Vekotin | 1:7ed7d128d225 | 41 | for (i=0; i<9; i++) { |
Vekotin | 1:7ed7d128d225 | 42 | input = key[i].read(); |
Vekotin | 1:7ed7d128d225 | 43 | if (!input) { //MIDIT |
Vekotin | 1:7ed7d128d225 | 44 | midi.write(MIDIMessage::NoteOn(48+i)); |
tanssisatu | 2:30d2ced09088 | 45 | //wait(0.25); |
tanssisatu | 2:30d2ced09088 | 46 | for(j=0; j<9; j++) { |
tanssisatu | 2:30d2ced09088 | 47 | input = key[j].read(); |
tanssisatu | 2:30d2ced09088 | 48 | if (!input) { |
tanssisatu | 2:30d2ced09088 | 49 | midi.write(MIDIMessage::NoteOn(48+j)); |
tanssisatu | 2:30d2ced09088 | 50 | //wait(0.25); |
tanssisatu | 2:30d2ced09088 | 51 | for(k=0; k<9; k++) { |
tanssisatu | 2:30d2ced09088 | 52 | input = key[k].read(); |
tanssisatu | 2:30d2ced09088 | 53 | if (!input) { |
tanssisatu | 2:30d2ced09088 | 54 | midi.write(MIDIMessage::NoteOn(48+k)); |
tanssisatu | 2:30d2ced09088 | 55 | //wait(0.25); |
tanssisatu | 2:30d2ced09088 | 56 | } |
tanssisatu | 2:30d2ced09088 | 57 | } |
tanssisatu | 2:30d2ced09088 | 58 | } |
tanssisatu | 2:30d2ced09088 | 59 | } |
Vekotin | 1:7ed7d128d225 | 60 | } |
tanssisatu | 2:30d2ced09088 | 61 | midi.write(MIDIMessage::NoteOff(48+i)); |
tanssisatu | 2:30d2ced09088 | 62 | midi.write(MIDIMessage::NoteOff(48+j)); |
tanssisatu | 2:30d2ced09088 | 63 | midi.write(MIDIMessage::NoteOff(48+k)); |
Vekotin | 1:7ed7d128d225 | 64 | |
tanssisatu | 2:30d2ced09088 | 65 | wait(0.25); |
tanssisatu | 2:30d2ced09088 | 66 | |
tanssisatu | 2:30d2ced09088 | 67 | } |
Vekotin | 1:7ed7d128d225 | 68 | /* pc.printf("Digital input %d", i); //terminal viesti |
tanssisatu | 2:30d2ced09088 | 69 | pc.printf(": %d\n\r", key[i].read());*/ |
tanssisatu | 2:30d2ced09088 | 70 | |
Vekotin | 1:7ed7d128d225 | 71 | |
Vekotin | 1:7ed7d128d225 | 72 | /* pc.printf("\n\r"); |
Vekotin | 1:7ed7d128d225 | 73 | wait(1); */ |
Vekotin | 0:9720755e6762 | 74 | } |
Vekotin | 0:9720755e6762 | 75 | } |