Bestand Tom Lankhorst

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    emg(A0); //Analog input
00006 Ticker      sample_timer;
00007 HIDScope    scope(1);
00008 
00009 /** Sample function
00010  * this function samples the emg and sends it to HIDScope
00011  **/
00012 void sample()
00013 {
00014     /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
00015     double emg_value = emg.read();
00016     /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
00017     scope.set(0,emg_value);
00018     /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
00019     /* Finally, send all channels to the PC at once */
00020     scope.send();
00021 }
00022 
00023 int main()
00024 {
00025     /**Attach the 'sample' function to the timer 'sample_timer'.
00026     * this ensures that 'sample' is executed every... 0.002 seconds
00027     */
00028     sample_timer.attach(&sample, 0.002);
00029 
00030     /*empty loop, sample() is executed periodically*/
00031     while(1) {}
00032 }