Alberto Piganti
/
blip_piano
miniblip USB piano example
Fork of Fruit_Piano by
Diff: main.cpp
- Revision:
- 2:1cb69f19f49c
- Parent:
- 1:93bbcf91f356
--- a/main.cpp Mon Aug 18 01:58:34 2014 +0000 +++ b/main.cpp Thu Nov 26 09:27:00 2015 +0000 @@ -1,17 +1,16 @@ +// miniblip play sound - capacitative + keyboard out + #include "mbed.h" -#include "USBKeyboard.h" - -#define LOG(args...) // printf(args) +#include "USBKeyboard.h" #define THRESHOLD 2 -#define TOUCH_N 6 +#define TOUCH_N 5 -BusOut leds(LED1, LED2, LED3, LED4); Ticker tick; USBKeyboard keyboard; uint8_t key_map[] = {'a', 'f', 'd', 'g', 'd', 'h', 'j', 'k', 'l', ';', '\'', '\n'}; -PinName touch_pin[] = {A0, A3, A2, A4, A1, A5}; +PinName touch_pin[] = {P0_15, P0_14, P0_13, P0_12, P0_11}; DigitalInOut *p_touch_io[TOUCH_N]; uint16_t touch_data[TOUCH_N] = {0, }; @@ -34,13 +33,9 @@ touch_io->output(); touch_io->write(1); - if (0x01 == touch_data[i]) { // a measurement is about the threshold, get a touch - leds = 1 << i; + if (0x01 == touch_data[i]) { // Threshold, get a touch keyboard.putc(key_map[i]); - LOG("No %d key is touched\r\n", i); - } else if (0x80 == touch_data[i]) { // last 7 measurement is under the threshold, touch is released - leds = 0x00; - LOG("No %d key is released\r\n", i); + } else if (0x80 == touch_data[i]) { // Last 7 measurement is under the threshold, touch is released } } } @@ -48,6 +43,11 @@ int main() { // setup + + // Turn off miniblip buzzer + PwmOut speaker(P0_8); + speaker=0.0; + for (int i = 0; i < TOUCH_N; i++) { p_touch_io[i] = new DigitalInOut(touch_pin[i]); p_touch_io[i]->mode(PullDown);