Script voor het weergeven van 1 EMG signaal met behulp van een OLIMEX shield. Let hierbij goed op dat je de juiste pinnetjes op het OLIMEX shield verbonden hebt, in dit geval A0 als uitgang. Verder maken we gebruik van 3,3 Volt!

Dependencies:   HIDScope mbed

Fork of EMG by Tom Tom

Committer:
Annelotte
Date:
Thu Oct 12 13:14:42 2017 +0000
Revision:
21:c418b6e8196b
Parent:
20:97059009a491
Script voor het weergeven van 1 EMG signaal met behulp van het OLIMEX shield. Zorg hierbij dat de pinnetjes goed geplaatst zijn op het OLIMEX shield, uitgang A0 moet verbonden zijn en we werken met 3,3 Volt!

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
Annelotte 21:c418b6e8196b 5 AnalogIn emg0( A0 ); //Dit zijn de EMG signalen die binnen komen, bv. de ground en een signaal
Annelotte 21:c418b6e8196b 6 //AnalogIn emg1( A1 );
tomlankhorst 19:2bf824669684 7
Annelotte 21:c418b6e8196b 8 Ticker sample_timer; //Leest de analog input en verplaatst deze naar de HIDScope
Annelotte 21:c418b6e8196b 9 HIDScope scope( 1 );
tomlankhorst 18:21d8e7a81cf5 10 DigitalOut led(LED1);
vsluiter 2:e314bb3b2d99 11
Annelotte 21:c418b6e8196b 12
tomlankhorst 14:f83354387756 13 /** Sample function
tomlankhorst 14:f83354387756 14 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 15 **/
tomlankhorst 14:f83354387756 16 void sample()
vsluiter 2:e314bb3b2d99 17 {
tomlankhorst 19:2bf824669684 18 /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
tomlankhorst 19:2bf824669684 19 scope.set(0, emg0.read() );
Annelotte 21:c418b6e8196b 20 //scope.set(1, emg1.read() );
Annelotte 21:c418b6e8196b 21
tomlankhorst 19:2bf824669684 22 /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
tomlankhorst 19:2bf824669684 23 * Ensure that enough channels are available (HIDScope scope( 2 ))
tomlankhorst 20:97059009a491 24 * Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 25 scope.send();
tomlankhorst 18:21d8e7a81cf5 26 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 27 led = !led;
vsluiter 2:e314bb3b2d99 28 }
vsluiter 0:32bb76391d89 29
vsluiter 0:32bb76391d89 30 int main()
tomlankhorst 19:2bf824669684 31 {
tomlankhorst 14:f83354387756 32 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 19:2bf824669684 33 * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
vsluiter 4:8b298dfada81 34 */
Annelotte 21:c418b6e8196b 35 sample_timer.attach(&sample, 0.002); //Elke 0.002 seconde wordt er dus een signaal gegeven aan de HIDScope. Je kunt met deze ticker dus 250Hz als maximale frequentie (range) meten (want anderss aliasing).
tomlankhorst 15:0da764eea774 36
tomlankhorst 14:f83354387756 37 /*empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 38 while(1) {}
vsluiter 0:32bb76391d89 39 }