voor DION

Dependencies:   HIDScope mbed

Fork of EMG by Tom Tom

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HIDScope.h"
00003 
00004 //Define objects
00005 AnalogIn    emg0( A0 );
00006 AnalogIn    emg1( A1 );
00007 
00008 Ticker      sample_timer;
00009 HIDScope    scope( 2 );
00010 DigitalOut  led(LED1);
00011 DigitalOut  led2(LED_GREEN);
00012 
00013 /** Sample function
00014  * this function samples the emg and sends it to HIDScope
00015  **/
00016 void sample()
00017 {
00018     /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
00019     scope.set(0, emg0.read() );
00020     scope.set(1, emg1.read() );
00021     /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) 
00022     *  Ensure that enough channels are available (HIDScope scope( 2 ))
00023     *  Finally, send all channels to the PC at once */
00024     scope.send();
00025     /* To indicate that the function is working, the LED is toggled */
00026     led = !led;
00027 }
00028 
00029 int main()
00030 {   
00031     /**Attach the 'sample' function to the timer 'sample_timer'.
00032     * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
00033     */
00034     sample_timer.attach(&sample, 0.002);
00035 
00036     /*empty loop, sample() is executed periodically*/
00037     while(true) {
00038         }
00039 }