Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
oczeides
Date:
Thu Nov 26 13:07:50 2009 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 835b0c5a6f94 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 26 13:07:50 2009 +0000
@@ -0,0 +1,53 @@
+//----------------------------------------------------------------------------------------
+// Project:   MIDIExpressionPedal
+// Function:  use the mbed board to convert a potentiometr into a MIDI expression pedal
+// Author:    Dr.-Ing. O.C. Zeides, using some code from the Cookbook
+// Version:  26.11.2009
+//---------------------------------------------------------------------------------------- 
+
+#include "mbed.h"
+#include "MIDI.h"
+
+MIDI midi(p13, p14);           // our MIDI communication channel
+DigitalOut myled(LED1);        // status LED, should flash if we update the controller
+AnalogIn potentiometer(p20);   // here is where we connect our potentiometer
+
+float last_pot = 0.0;          // memorize the old potentiometer value
+float actual_pot;              // actual poentiometer value
+float hysterese = 0.1;         // only send new message if we have moved the potentiometer that far
+float fvalue = 0.0;
+
+int controllerNo = 1;          // MIDI controller No
+int channelNo = 1;             // MIDI channel No.
+int value = 0;                 // MIDI value for controller
+
+// send the new value to the controller
+void updateMIDIController(void)
+{
+   myled = 1;
+   fvalue = actual_pot * 127.0;
+   value = (int) fvalue;
+   midi.controller(controllerNo,value,channelNo);
+   wait(0.5);
+   myled = 0;
+} // updateMIDIController()
+
+int main() {
+   
+   while(1) { // do forever
+// get new pot value
+      actual_pot = potentiometer;
+// compare with last pot value  
+      if(actual_pot > (last_pot + hysterese))
+         updateMIDIController();
+      if(actual_pot < (last_pot - hysterese))
+         updateMIDIController();
+    
+      last_pot = actual_pot;   
+  
+   } // while
+   
+} // main()
+
+
+
diff -r 000000000000 -r 835b0c5a6f94 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 26 13:07:50 2009 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/32af5db564d4