Overzetten
Dependencies: HIDScope MODSERIAL mbed
main.cpp
- Committer:
- ThomBMT
- Date:
- 2018-10-05
- Revision:
- 4:a1691164d879
- Parent:
- 3:4f5a67f4170b
- Child:
- 5:0ae4951e9b81
File content as of revision 4:a1691164d879:
#include "mbed.h" #include "MODSERIAL.h" #include "HIDScope.h" MODSERIAL pc(USBTX, USBRX); DigitalOut DirectionPin1(D4); PwmOut PwmPin1(D5); DigitalOut DirectionPin2(D7); PwmOut PwmPin2(D6); DigitalIn Knop1(D3); DigitalIn Knop2(D2); DigitalIn Knop3(PTA4); DigitalIn Knop4(PTC6); //Define objects AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); Ticker sample_timer; //HIDScope scope( 2 ); DigitalOut led(LED1); int Turn_Motor1() { if(Knop1==false) // Motor 1 rotates CW { float u = 0.8f; //determine useful value, this is not final DirectionPin1 = u > 0.0f; //either true or false // True = CW, for False = CW PwmPin1 = fabs(u); PwmPin2 = fabs(0.0); } else if (Knop3==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks { float u = 0.8f; DirectionPin1 = u < 0.0f; PwmPin1 = fabs(u); PwmPin2 = fabs(0.0); } else { float u = 0.0f; PwmPin1 = fabs(u); } return 0; } int Turn_Motor2() { if (Knop2==false) { float u = 0.8f; DirectionPin2 = u < 0.0f; PwmPin1 = fabs(0.0); PwmPin2 = fabs(u); } else if (Knop4==false) { float u = 0.8f; DirectionPin2 = u > 0.0f; PwmPin1 = fabs(0.0); PwmPin2 = fabs(u); } else { float u = 0.0f; PwmPin2 = fabs(u); } return 0; } /* void sample() { scope.set(0, emg0.read() ); scope.set(1, emg1.read() ); scope.send(); led = !led; } */ int main() { pc.baud(115200); // sample_timer.attach(&sample, 0.002); PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz for(;;) { Turn_Motor1(); Turn_Motor2(); } }