try this for a change

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed

Fork of EMG_5 by Ralph Gerlings

Committer:
tomlankhorst
Date:
Thu Sep 22 08:04:14 2016 +0000
Revision:
18:21d8e7a81cf5
Parent:
16:9f7797ffd0fb
Child:
19:2bf824669684
Updated HIDScope lib. ; Added blinking LED in sample fn.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
vsluiter 0:32bb76391d89 3
vsluiter 4:8b298dfada81 4 //Define objects
tomlankhorst 14:f83354387756 5 AnalogIn emg(A0); //Analog input
tomlankhorst 14:f83354387756 6 Ticker sample_timer;
tomlankhorst 14:f83354387756 7 HIDScope scope(1);
tomlankhorst 18:21d8e7a81cf5 8 DigitalOut led(LED1);
vsluiter 2:e314bb3b2d99 9
tomlankhorst 14:f83354387756 10 /** Sample function
tomlankhorst 14:f83354387756 11 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 12 **/
tomlankhorst 14:f83354387756 13 void sample()
vsluiter 2:e314bb3b2d99 14 {
tomlankhorst 14:f83354387756 15 /* First, sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
tomlankhorst 14:f83354387756 16 double emg_value = emg.read();
tomlankhorst 14:f83354387756 17 /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
vsluiter 11:ce72ec658a95 18 scope.set(0,emg_value);
tomlankhorst 16:9f7797ffd0fb 19 /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
tomlankhorst 14:f83354387756 20 /* Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 21 scope.send();
tomlankhorst 18:21d8e7a81cf5 22 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 23 led = !led;
vsluiter 2:e314bb3b2d99 24 }
vsluiter 0:32bb76391d89 25
vsluiter 0:32bb76391d89 26 int main()
vsluiter 0:32bb76391d89 27 {
tomlankhorst 14:f83354387756 28 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 18:21d8e7a81cf5 29 * this ensures that 'sample' is executed every... 0.01 seconds
vsluiter 4:8b298dfada81 30 */
tomlankhorst 18:21d8e7a81cf5 31 sample_timer.attach(&sample, 0.01);
tomlankhorst 15:0da764eea774 32
tomlankhorst 14:f83354387756 33 /*empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 34 while(1) {}
vsluiter 0:32bb76391d89 35 }