k

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 
00012 /** Sample function
00013  * this function samples the emg and sends it to HIDScope
00014  **/
00015 void sample()
00016 {
00017     /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
00018     scope.set(0, emg0.read() );
00019     scope.set(1, emg1.read() );
00020     /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) 
00021     *  Ensure that enough channels are available (HIDScope scope( 2 ))
00022     *  Finally, send all channels to the PC at once */
00023     scope.send();
00024     /* To indicate that the function is working, the LED is toggled */
00025     led = !led;
00026 }
00027 
00028 int main()
00029 {   
00030     /**Attach the 'sample' function to the timer 'sample_timer'.
00031     * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
00032     */
00033     sample_timer.attach(&sample, 0.002);
00034 
00035     /*empty loop, sample() is executed periodically*/
00036     while(1) {}
00037 }