Honmaka Astro MicroControler sample PluseMotor Sample Ver 3
Fork of PulseMotor2 by
Revision 2:61ec30f77bc3, committed 2015-01-11
- Comitter:
- Honmaka
- Date:
- Sun Jan 11 08:28:16 2015 +0000
- Parent:
- 1:c533a17dccc0
- Commit message:
- PulseMotor Ver3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jan 10 06:25:14 2015 +0000 +++ b/main.cpp Sun Jan 11 08:28:16 2015 +0000 @@ -5,7 +5,15 @@ DigitalIn MotorDirectionSw(p6); DigitalOut MotorDirectionOut(p7); +//Add push SW +DigitalIn WestPushSw(p8); +DigitalIn EastPushSw(p9); + int main() { + //Add + int PreStateWest = 1; + int PreStateEast = 1; + MotorSpeedSw.mode(PullUp); MotorDirectionSw.mode(PullUp); //Dorection @@ -18,7 +26,47 @@ else { //Half Speed PulseMotor.period_us(83140*2); PulseMotor.pulsewidth_us((83140*2)/2); - } + } + + //Add + WestPushSw.mode(PullUp); + EastPushSw.mode(PullUp); + while(1) { + if (WestPushSw != PreStateWest) { + if (WestPushSw == 0) { + //pushed West SW + //double speed + PulseMotor.period_us(83140/2); + PulseMotor.pulsewidth_us((83140/2) /2); + } + else { + //relese West SW + //normal speed + PulseMotor.period_us(83140); + PulseMotor.pulsewidth_us(83140 /2); + } + } + if (EastPushSw != PreStateEast) { + if (EastPushSw == 0) { + //pushed East SW + //Stop + PulseMotor.period_us(83140); + PulseMotor.pulsewidth_us(0); + } + else { + //relese East SW + //normal speed + PulseMotor.period_us(83140); + PulseMotor.pulsewidth_us(83140 /2); + } + } + //Save SW state + PreStateWest = WestPushSw; + PreStateEast = EastPushSw; + + wait(0.01); } } + +