EMG aansluiten op motor
Dependencies: FastPWM HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 1:83531c955134
- Parent:
- 0:73cf7fc57ab7
- Child:
- 2:9c1bdcf6bc26
--- a/main.cpp Thu Oct 11 13:58:41 2018 +0000 +++ b/main.cpp Thu Oct 11 14:17:03 2018 +0000 @@ -8,11 +8,13 @@ FastPWM pwmpin2(D6); // SPECIFIC PIN (hoeft niet aangesloten te worden) Tells you how fast the motor has to go (later: pwmpin.write will tell you the duty cycle, aka how much voltage the motor gets) DigitalOut directionpin1(D4); // SPECIFIC PIN (hoeft niet aangesloten te worden) Direction value (0-1) that the mbed will give the motor: in which direction the motor must rotate DigitalOut directionpin2(D7); // SPECIFIC PIN (hoeft niet aangesloten te worden) Direction value (0-1) that the mbed will give the motor: in which direction the motor must rotate -AnalogIn emg0( A0 ); // EMG on Bicep 1 -AnalogIn emg1( A1 ); // EMG on Bicep 2 -DigitalOut led(LED1); // Check for Sample function -InterruptIn button1(PTC6); // Interrupt1 for EMG 1 -InterruptIn button2( +AnalogIn emg0( A0 ); // EMG on Bicep 1 +AnalogIn emg1( A1 ); // EMG on Bicep 2 +DigitalOut led(LED1); // Check for Sample function +InterruptIn button1(PTC6); // Interrupt 1 for EMG 1 +DigitalOut ledb1(LED_RED); // Check for button_pressed1 function +InterruptIn button2(PTA4); // Interrupt 2 for EMG 2 +DigitalOut ledb2(LED_GREEN); // check for button_pressed2 function // Define variables Ticker sample_timer; // Ticker for EMG sample function @@ -34,6 +36,18 @@ led = !led; } +void button_pressed1() // Indicates direction of motor 1 becomes negative + { + ledb1 = 0; // Turns on red led as indication of negative direction for motor 1 + u1 = -u1; // Direction for motor 1 becomes negative + } + +void button_pressed2() // Indicates direction of motor 2 becomes negative + { + ledb2 = 0; // Turns on green led as indication of negative direction for motor 2 + u2 = -u2; // Direction for motor 2 becomes negative + } + void motorfunction() // Function for motor control { u1 = EMG1_scale; // motor control signal @@ -49,5 +63,7 @@ sample_timer.attach(&sample, 0.002); // 500 Hz pwmpin1.period_us(60.0); //60 microseconds PWM period, 16.7 kHz, defines all PWM pins (only needs to be done once) motor.attach(motorfunction,0.5); + button1.fall(&button_pressed1); // whenever button 1 falls, execute button_pressed1 function (blinks led red and changes motor direction) + button2.fall(&button_pressed2); // whenever button 2 falls, execute button_pressed1 function (blinks led green and changes motor direction) while(1) {} } \ No newline at end of file