emg trial
Dependencies: FastPWM HIDScope MODSERIAL mbed biquadFilter
Diff: main.cpp
- Revision:
- 1:e81ca29ae626
- Parent:
- 0:94b5c70f818b
- Child:
- 2:0189c5170834
--- a/main.cpp Mon Sep 24 14:39:45 2018 +0000 +++ b/main.cpp Mon Oct 08 12:50:16 2018 +0000 @@ -1,42 +1,48 @@ #include "mbed.h" +#include "HIDScope.h" #include "MODSERIAL.h" -PwmOut pwmpin(D5); -DigitalOut directionpin(D4); -AnalogIn Pot_meter(A0); -DigitalIn But2(D7); - + +// Two analog inputs to read from +AnalogIn a0(A0); +AnalogIn a1(A1); +DigitalOut ledr(LED_RED); MODSERIAL pc(USBTX, USBRX); -Ticker Ticker_direction; -Ticker Ticker_But; -//InterruptIn IntBut(D7); - -float x=0; -void Potread() - { - x = Pot_meter.read(); - pc.printf("%d\n\r",x); - } +// Define the HIDScope and Ticker objects +HIDScope scope(1); +Ticker scopeTimer; +Ticker controllerTimer; +Ticker Print_emg; + +void controlAndMeasure() +{ + // Do some control + // ** control code here ** + + // Store values in the scope + scope.set(0,a0.read()); + //scope.set(1,a1.read()); +} -void Direction() - { - float u = -0.3f; //determine useful value, -0.3f is just an example - directionpin = u > 0.0f; //either true or false - pwmpin = fabs(u); //pwm duty cycle can only be positive, floating point absolute value - pc.printf("Test\r\n"); - } +void printEMG () +{ + pc.printf("EMG= %f \n/r", a0.read()); +} + + int main() { pc.baud(115200); - Ticker_direction.attach(Direction, 0.001); - Ticker_But.attach(Potread,1); - //IntBut.fall(Potread); + // Attach the HIDScope::send method from the scope object to the timer at 50Hz + scopeTimer.attach_us(&scope, &HIDScope::send, 2e4); + Print_emg.attach(printEMG, 0.5); + + // Attach the controlAndMeasure method to the controller timer at 1kHz + controllerTimer.attach_us(&controlAndMeasure, 1e3); - pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz - while (true) - { - } + while(1) { } + } \ No newline at end of file