A piano built with a basket of fruit, a microcontroller and a computer.
Fork of MaKeyMaKey_mbed_version by
A piano built with a basket of fruit, a microcontroller and a computer.
The idea is from Makey Makey, but uses different hardware and software. An mbed enabled microcontroller with USB is used.
Hardware
- An Arch board
- A basket of fruit
- A computer with AC power
- some wires
Software
- Click this link to import the program to mbed online compiler.
- Compile the code and download the binary file - Fruit_Piano_LPC11U24.bin.
- Connect the Arch board to the computer and long press the button, a USB drive named CRP DISABLD will pop up.
- Delete firmware.bin and copy Arch_GPIO_Ex1_LPC11U24.bin to the USB drive.
- Quick press the button to run the program
- Wire some apples or bananas to A0 - A5 (P0_11 - P0_14, P0_16, P0_22) pins of the Arch board
- Open Fruit Piano and play
Have fun!
main.cpp
- Committer:
- yihui
- Date:
- 2014-08-18
- Revision:
- 1:93bbcf91f356
- Parent:
- 0:4755a81efb1d
File content as of revision 1:93bbcf91f356:
#include "mbed.h" #include "USBKeyboard.h" #define LOG(args...) // printf(args) #define THRESHOLD 2 #define TOUCH_N 6 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}; DigitalInOut *p_touch_io[TOUCH_N]; uint16_t touch_data[TOUCH_N] = {0, }; void detect(void) { for (int i = 0; i < TOUCH_N; i++) { uint8_t count = 0; DigitalInOut *touch_io = p_touch_io[i]; touch_io->input(); touch_data[i] <<= 1; while (touch_io->read()) { count++; if (count > THRESHOLD) { touch_data[i] |= 0x01; break; } } touch_io->output(); touch_io->write(1); if (0x01 == touch_data[i]) { // a measurement is about the threshold, get a touch leds = 1 << i; 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); } } } int main() { // setup for (int i = 0; i < TOUCH_N; i++) { p_touch_io[i] = new DigitalInOut(touch_pin[i]); p_touch_io[i]->mode(PullDown); p_touch_io[i]->output(); p_touch_io[i]->write(1); } tick.attach(detect, 1.0 / 40.0); while(1) { // do something wait(1); } }