@@ -15,6 +15,19 @@ class KitronikPicoRobotBuggy:
1515 button = Pin (0 ,Pin .IN ,Pin .PULL_DOWN )
1616
1717#Motors: controls the motor directions and speed for both motors
18+ def _initMotors (self ):
19+ self .motor1Forward = PWM (Pin (20 ))
20+ self .motor1Reverse = PWM (Pin (19 ))
21+ self .motor2Forward = PWM (Pin (6 ))
22+ self .motor2Reverse = PWM (Pin (7 ))
23+ #set the PWM to 10Khz
24+ self .motor1Forward .freq (10000 )
25+ self .motor1Reverse .freq (10000 )
26+ self .motor2Forward .freq (10000 )
27+ self .motor2Reverse .freq (10000 )
28+ self .motorOff ("l" )
29+ self .motorOff ("r" )
30+
1831 def motorOn (self ,motor , direction , speed ):
1932 #cap speed to 0-100%
2033 if (speed < 0 ):
@@ -256,15 +269,7 @@ def beepHorn(self):
256269#initialisation code for using:
257270 #defaults to the standard pins and freq for the kitronik board, but could be overridden
258271 def __init__ (self ):
259- self .motor1Forward = PWM (Pin (20 ))
260- self .motor1Reverse = PWM (Pin (19 ))
261- self .motor2Forward = PWM (Pin (6 ))
262- self .motor2Reverse = PWM (Pin (7 ))
263- #set the PWM to 10Khz
264- self .motor1Forward .freq (10000 )
265- self .motor1Reverse .freq (10000 )
266- self .motor2Forward .freq (10000 )
267- self .motor2Reverse .freq (10000 )
272+ self ._initMotors ()
268273 self .servos = []
269274 self ._initServos ()
270275 #connect the servos by default on construction - advanced uses can disconnect them if required.
0 commit comments