Otto Zeides / Mbed 2 deprecated MIDIExpressionPedal

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //----------------------------------------------------------------------------------------
00002 // Project:   MIDIExpressionPedal
00003 // Function:  use the mbed board to convert a potentiometr into a MIDI expression pedal
00004 // Author:    Dr.-Ing. O.C. Zeides, using some code from the Cookbook
00005 // Version:  26.11.2009
00006 //---------------------------------------------------------------------------------------- 
00007 
00008 #include "mbed.h"
00009 #include "MIDI.h"
00010 
00011 MIDI midi(p13, p14);           // our MIDI communication channel
00012 DigitalOut myled(LED1);        // status LED, should flash if we update the controller
00013 AnalogIn potentiometer(p20);   // here is where we connect our potentiometer
00014 
00015 float last_pot = 0.0;          // memorize the old potentiometer value
00016 float actual_pot;              // actual poentiometer value
00017 float hysterese = 0.1;         // only send new message if we have moved the potentiometer that far
00018 float fvalue = 0.0;
00019 
00020 int controllerNo = 1;          // MIDI controller No
00021 int channelNo = 1;             // MIDI channel No.
00022 int value = 0;                 // MIDI value for controller
00023 
00024 // send the new value to the controller
00025 void updateMIDIController(void)
00026 {
00027    myled = 1;
00028    fvalue = actual_pot * 127.0;
00029    value = (int) fvalue;
00030    midi.controller(controllerNo,value,channelNo);
00031    wait(0.5);
00032    myled = 0;
00033 } // updateMIDIController()
00034 
00035 int main() {
00036    
00037    while(1) { // do forever
00038 // get new pot value
00039       actual_pot = potentiometer;
00040 // compare with last pot value  
00041       if(actual_pot > (last_pot + hysterese))
00042          updateMIDIController();
00043       if(actual_pot < (last_pot - hysterese))
00044          updateMIDIController();
00045     
00046       last_pot = actual_pot;   
00047   
00048    } // while
00049    
00050 } // main()
00051 
00052 
00053