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 MODSERIAL QEI biquadFilter mbed
Fork of EMG_converter_code by
Diff: main.cpp
- Revision:
- 5:46e201518dd3
- Parent:
- 4:fd29407c3115
- Child:
- 6:ec965bb75d40
--- a/main.cpp Mon Oct 26 14:22:40 2015 +0000
+++ b/main.cpp Tue Oct 27 09:28:17 2015 +0000
@@ -5,6 +5,7 @@
//Define objects
AnalogIn emg(A0); //Analog of EMG input
Ticker sample_timer;
+Ticker motor_timer;
HIDScope scope(2); // Instantize a 2-channel HIDScope object
DigitalIn button1(PTA4);//test button for starting motor 1
DigitalOut led1(LED_RED);
@@ -36,14 +37,19 @@
scope.set(0,emg_value);//set emg signal to scope in channel 1
scope.set(1,onoffsignal);//set filtered signal to scope in channel 2
scope.send();//send the signals to the scope
+ pc.printf("emg signal %f, filtered signal %f /n",emg_value,onoffsignal);
}
-double normalcal(){
- double signalmeasure =emg.read();
- if (signalmeasure > maxcal){
- signalmeasure = maxcal;
- }
- return maxcal;
-}
+
+void checkmotor(){
+ if(onoffsignal<=0.02){
+ led1.write(0);
+ led2.write(1);
+ }
+ else if(onoffsignal >= 0.05){
+ led1.write(1);
+ led2.write(0);
+ }
+ }
int main()
{
@@ -53,28 +59,22 @@
bool calyes=0;
if(calyes==1){
+ pc.printf("start the emg.read");
sample_timer.attach(&filter, 0.002);//continously execute the EMG reader and filter
+ motor_timer.attach(&filter, 0.002);//continously execute the motor controller
}
- while(1){
- if(button1.read()==false){
- for(int n =0; n<5000;n++){
- double signalmeasure =emg.read();
- pc.printf("%d", signalmeasure);
- if (signalmeasure > maxcal){
- signalmeasure = maxcal;
+while(1){ if(button1.read()==false){
+ for(int n =0; n<5000;n++){
+ double signalmeasure =emg.read();
+ pc.printf("%f \n", signalmeasure);
+ if (signalmeasure > maxcal){
+ maxcal = signalmeasure;
+ }
}
calyes=1;
- }
+ pc.printf("the max emg value is %f and calyes is %d", maxcal, calyes);
}
-
- // pc.printf("%f \n", onoffsignal);
- if(onoffsignal<=0.02){
- led1.write(0);
- led2.write(1);
- }
- else if(onoffsignal >= 0.05){
- led1.write(1);
- led2.write(0);
- }
- }
+
+
+}
}
\ No newline at end of file
