mbed Android Piano
This project uses the mbed RPC library to interface with a modified Adafruit Blutooth app. The application sends RPC calls to the mbed over the Adafruit Bluefruit LE UART Friend serial connection. The mbed then uses the Class D audio amp and speaker to generate the correct tone.
Hardware Assembly
mbed | Class D Amp | =Speaker | =Bluetooth module |
---|---|---|---|
VU | PWR + | Vin | |
p21 | IN+ | ||
p27 | TXO | ||
p28 | RXI | ||
GND | PWR- | GND | |
GND | IN- | CTS | |
OUT+ | + | ||
OUT- | - |
Optional potentiometer can placed on VOL pins of Class D amp.
mbed Code
//Code for mbed Android Piano project //Based on RPC Example code #include "mbed.h" #include "mbed_rpc.h" // Blutooth Serial pc(p28, p27); // Define RPC function void moveTo(Arguments *in, Reply *out); RPCFunction rpcMove(&moveTo, "moveTo"); // Speaker Control double pwmVal; PwmOut PWM(p21); int main() { char buf[256], outbuf[256]; while(1) { //Get Serial Arguments pc.gets(buf, 256); //Call the static call method on the RPC class RPC::call(buf, outbuf); } } // Make sure the method takes in Arguments and Reply objects. void moveTo (Arguments *in, Reply *out){ pwmVal = in->getArg<float>(); PWM.period(1.0/(pwmVal));//Set speaker Frequency PWM = 0.5;//Set speaker amplitude }
Import libraryRPC_Function_Example
Android controlled
Blutooth Application
Modified in Android Studio as a Windows Forms application. You can download the project below.
https://www.mediafire.com/?n1ha56cdw1zf1ap
Running
- Compile and download the mbed code to the mbed
- Leave mbed connected
- Open the Adafruit application on your phone
- Connect to the module and tap UART
- Click the keys to play tones
Demo
Please log in to post comments.