Modifications

Sauter à la navigation Sauter à la recherche
Ligne 75 : Ligne 75 :  
== Fixer le sens de rotation ==
 
== Fixer le sens de rotation ==
 
To set the direction, call '''run(direction)''' where direction is a constant from one of the following:
 
To set the direction, call '''run(direction)''' where direction is a constant from one of the following:
 +
* '''Adafruit_MotorHAT.FORWARD''' - DC motor spins forward
 +
* '''Adafruit_MotorHAT.BACKWARD''' - DC motor spins forward
 +
* '''Adafruit_MotorHAT.RELEASE''' - DC motor is 'off', not spinning but will also not hold its place.
 +
 +
<syntaxhighlight lang="python">
 +
while (True):
 +
print "Forward! "
 +
myMotor.run(Adafruit_MotorHAT.FORWARD)
 +
 +
print "\tSpeed up..."
 +
for i in range(255):
 +
myMotor.setSpeed(i)
 +
time.sleep(0.01)
 +
 +
print "\tSlow down..."
 +
for i in reversed(range(255)):
 +
myMotor.setSpeed(i)
 +
time.sleep(0.01)
 +
 +
print "Backward! "
 +
myMotor.run(Adafruit_MotorHAT.BACKWARD)
 +
 +
print "\tSpeed up..."
 +
for i in range(255):
 +
myMotor.setSpeed(i)
 +
time.sleep(0.01)
 +
 +
print "\tSlow down..."
 +
for i in reversed(range(255)):
 +
myMotor.setSpeed(i)
 +
time.sleep(0.01)
 +
 +
print "Release"
 +
myMotor.run(Adafruit_MotorHAT.RELEASE)
 +
time.sleep(1.0)
 +
</syntaxhighlight>
    
{{Rasp-Hat-Moteur-TRAILER}}
 
{{Rasp-Hat-Moteur-TRAILER}}
29 917

modifications

Menu de navigation