bbcmicrobit / bbcmicrobit/micropython
Analog Pins don't correctly switch to Digital
- Dominant language
- C
- Stars
- 646
- Forks
- 290
- PR merge metrics
- No merged PRs in 30d
Description
We're using 4 pins to control 2 dc motors, 2 pins for each motor. PWM on one pin or the other depending on direction. The other pin is set to a 0 (write_digital). To coast to a stop, set both pins to 0 - this always works regardless of analog or digital. To use regenerative braking, set both pins to 1 - this goes wrong if use write_digital and only works by using write_analog with 1023 for PWM.
The following complete program "should" work I think to set both pins to high after driving the motors forward with PWM value of 600. However, instead of the motors stopping, they start moving backwards slowly. If the "write_digital(1) are replaced with "wire_analog(1023)" then it all works as it should.
from microbit import *
pin12.write_analog(600)
pin8.write_digital(0)
pin16.write_analog(600)
pin14.write_digital(0)
sleep(2000)
pin12.write_digital(1)
pin8.write_digital(1)
pin16.write_digital(1)
pin14.write_digital(1)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.