Honmaka Astro MicroControler sample PluseMotor Sample Ver 2
Fork of PulseMotor by
Revision 1:c533a17dccc0, committed 2015-01-10
- Comitter:
- Honmaka
- Date:
- Sat Jan 10 06:25:14 2015 +0000
- Parent:
- 0:27fe3b05f1fc
- Commit message:
- PulseMotor sample program with switch
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Jan 04 07:55:14 2015 +0000 +++ b/main.cpp Sat Jan 10 06:25:14 2015 +0000 @@ -1,10 +1,24 @@ #include "mbed.h" PwmOut PulseMotor(p21); +DigitalIn MotorSpeedSw(p5); +DigitalIn MotorDirectionSw(p6); +DigitalOut MotorDirectionOut(p7); int main() { - PulseMotor.period_us(83140); - PulseMotor.pulsewidth_us(83140/2); + MotorSpeedSw.mode(PullUp); + MotorDirectionSw.mode(PullUp); + //Dorection + MotorDirectionOut = MotorDirectionSw; + //Speed + if (MotorSpeedSw == 1) { //Normal Speed + PulseMotor.period_us(83140); + PulseMotor.pulsewidth_us(83140/2); + } + else { //Half Speed + PulseMotor.period_us(83140*2); + PulseMotor.pulsewidth_us((83140*2)/2); + } while(1) { } }