A piano built with a basket of fruit, a microcontroller and a computer.

Dependencies:   USBDevice mbed

Fork of MaKeyMaKey_mbed_version by Seeed

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.

https://raw.githubusercontent.com/xiongyihui/piano/master/piano.png

https://github.com/xiongyihui/piano/raw/master/hardware.jpg

Hardware

  • An Arch board
  • A basket of fruit
  • A computer with AC power
  • some wires

Software

  1. Click this link to import the program to mbed online compiler.
  2. Compile the code and download the binary file - Fruit_Piano_LPC11U24.bin.
  3. Connect the Arch board to the computer and long press the button, a USB drive named CRP DISABLD will pop up.
  4. Delete firmware.bin and copy Arch_GPIO_Ex1_LPC11U24.bin to the USB drive.
  5. Quick press the button to run the program
  6. Wire some apples or bananas to A0 - A5 (P0_11 - P0_14, P0_16, P0_22) pins of the Arch board
  7. Open Fruit Piano and play

Have fun!

Committer:
yihui
Date:
Mon Aug 18 01:58:34 2014 +0000
Revision:
1:93bbcf91f356
Parent:
0:4755a81efb1d
Custom for Fruit Piano

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:4755a81efb1d 1 #include "mbed.h"
yihui 0:4755a81efb1d 2 #include "USBKeyboard.h"
yihui 0:4755a81efb1d 3
yihui 0:4755a81efb1d 4 #define LOG(args...) // printf(args)
yihui 0:4755a81efb1d 5
yihui 0:4755a81efb1d 6 #define THRESHOLD 2
yihui 0:4755a81efb1d 7 #define TOUCH_N 6
yihui 0:4755a81efb1d 8
yihui 0:4755a81efb1d 9 BusOut leds(LED1, LED2, LED3, LED4);
yihui 0:4755a81efb1d 10 Ticker tick;
yihui 0:4755a81efb1d 11 USBKeyboard keyboard;
yihui 0:4755a81efb1d 12
yihui 1:93bbcf91f356 13 uint8_t key_map[] = {'a', 'f', 'd', 'g', 'd', 'h', 'j', 'k', 'l', ';', '\'', '\n'};
yihui 1:93bbcf91f356 14 PinName touch_pin[] = {A0, A3, A2, A4, A1, A5};
yihui 0:4755a81efb1d 15 DigitalInOut *p_touch_io[TOUCH_N];
yihui 0:4755a81efb1d 16
yihui 1:93bbcf91f356 17 uint16_t touch_data[TOUCH_N] = {0, };
yihui 0:4755a81efb1d 18
yihui 0:4755a81efb1d 19 void detect(void)
yihui 0:4755a81efb1d 20 {
yihui 0:4755a81efb1d 21 for (int i = 0; i < TOUCH_N; i++) {
yihui 0:4755a81efb1d 22 uint8_t count = 0;
yihui 0:4755a81efb1d 23 DigitalInOut *touch_io = p_touch_io[i];
yihui 0:4755a81efb1d 24
yihui 0:4755a81efb1d 25 touch_io->input();
yihui 0:4755a81efb1d 26 touch_data[i] <<= 1;
yihui 0:4755a81efb1d 27 while (touch_io->read()) {
yihui 0:4755a81efb1d 28 count++;
yihui 0:4755a81efb1d 29 if (count > THRESHOLD) {
yihui 0:4755a81efb1d 30 touch_data[i] |= 0x01;
yihui 0:4755a81efb1d 31 break;
yihui 0:4755a81efb1d 32 }
yihui 0:4755a81efb1d 33 }
yihui 0:4755a81efb1d 34 touch_io->output();
yihui 0:4755a81efb1d 35 touch_io->write(1);
yihui 0:4755a81efb1d 36
yihui 0:4755a81efb1d 37 if (0x01 == touch_data[i]) { // a measurement is about the threshold, get a touch
yihui 0:4755a81efb1d 38 leds = 1 << i;
yihui 0:4755a81efb1d 39 keyboard.putc(key_map[i]);
yihui 0:4755a81efb1d 40 LOG("No %d key is touched\r\n", i);
yihui 0:4755a81efb1d 41 } else if (0x80 == touch_data[i]) { // last 7 measurement is under the threshold, touch is released
yihui 0:4755a81efb1d 42 leds = 0x00;
yihui 0:4755a81efb1d 43 LOG("No %d key is released\r\n", i);
yihui 0:4755a81efb1d 44 }
yihui 0:4755a81efb1d 45 }
yihui 0:4755a81efb1d 46 }
yihui 0:4755a81efb1d 47
yihui 0:4755a81efb1d 48 int main()
yihui 0:4755a81efb1d 49 {
yihui 0:4755a81efb1d 50 // setup
yihui 0:4755a81efb1d 51 for (int i = 0; i < TOUCH_N; i++) {
yihui 0:4755a81efb1d 52 p_touch_io[i] = new DigitalInOut(touch_pin[i]);
yihui 0:4755a81efb1d 53 p_touch_io[i]->mode(PullDown);
yihui 0:4755a81efb1d 54 p_touch_io[i]->output();
yihui 0:4755a81efb1d 55 p_touch_io[i]->write(1);
yihui 0:4755a81efb1d 56 }
yihui 0:4755a81efb1d 57
yihui 1:93bbcf91f356 58 tick.attach(detect, 1.0 / 40.0);
yihui 0:4755a81efb1d 59
yihui 0:4755a81efb1d 60 while(1) {
yihui 0:4755a81efb1d 61 // do something
yihui 0:4755a81efb1d 62 wait(1);
yihui 0:4755a81efb1d 63 }
yihui 0:4755a81efb1d 64 }