Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope QEI biquadFilter mbed
Fork of EMG_Controller_5 by
servoController.h
- Committer:
- LeeJon
- Date:
- 2016-10-26
- Revision:
- 8:aa03407660f1
- Parent:
- 7:eed677b636d3
- Child:
- 11:c8b6a2b314c3
File content as of revision 8:aa03407660f1:
#include "mbed.h" Serial pc(USBTX,USBRX); PwmOut ServoPWMpin(D9); Timeout resetter; bool readtime = 1; double ServoAngle = 89 ; float Pulsew = 0.0015; double treshold = 0.3; bool binary_input_signal = 0; bool binary_input_signal_previous = 0; void set21(){ readtime = 1; } void control_servo(double input_signal){ pc.printf("/n/r %f", input_signal); if (input_signal > treshold){ // convert the emg to a zero or a one binary_input_signal = 1; } else { binary_input_signal = 0; } if((( binary_input_signal!= binary_input_signal_previous)&& binary_input_signal)&& readtime){ readtime = 0; resetter.attach(&set21, 1); if( ServoAngle < 45){ // check wether it is more opened or closed ServoAngle = 89; // open } else{ ServoAngle = 1; // close } } Pulsew = 0.0015+(ServoAngle)/180000; // calculate the pulsewidth in the range 1 to 2 milliseconds ServoPWMpin.pulsewidth(Pulsew); // write the pulsewidth pc.printf("\n\r Pulsew is %f",Pulsew); binary_input_signal_previous = binary_input_signal; }