code
Dependencies: FastPWM HIDScope mbed
Fork of Motor_Rotator by
Revision 2:328fa2eb6437, committed 2018-09-27
- Comitter:
- Iriskolenbrander9
- Date:
- Thu Sep 27 14:06:44 2018 +0000
- Parent:
- 1:aab087815027
- Commit message:
- Motor 1 working, hidscope is not.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r aab087815027 -r 328fa2eb6437 main.cpp --- a/main.cpp Thu Sep 27 13:09:29 2018 +0000 +++ b/main.cpp Thu Sep 27 14:06:44 2018 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "HIDScope.h" -// Motor 1 has PWM-pin D5 and direction-pin D4 +// Motor 1 has PWM-pin D6 and direction-pin D7 AnalogIn pot1(A0); DigitalOut directionpin(D7); @@ -9,20 +9,22 @@ HIDScope scope(1); // We’re going to send 1 channel of data Ticker AInTicker; -void ReadAnalogInAndFilter() -{ - float a = 2.0f*pot1-1.0f; - scope.set(0, a); // Brightness is saved in the first scope. +void ReadAnalogInAndFilter(){ + float a = 2.0f*pot1-1.0f; //value of the potmeter is rescaled between -1 and 1 + scope.set(0, a); // save scaled potmeter value scope.send(); // send what's in scope memory to PC } +void SetMotorSpeed(){ + float u = 2.0f*pot1-1.0f; + directionpin = u > 0.0f; //either true or false, output 0 or 1 + pwmpin = fabs(u); //pwm duty cycle can only be positive, floating point absolute value of the potmeter value +} + int main(){ pwmpin.period_us(60); + while(true){ AInTicker.attach(&ReadAnalogInAndFilter, 0.01f); - while (true) { - float u = 2.0f*pot1-1.0f; //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 - wait(0.001f); + SetMotorSpeed(); } } \ No newline at end of file