Python Library for SB Motor-shield
SB Components' Motor-Shield python library v.2.
Pi Motor-Shield Library Reference:
Motor
Class describing a set of Motor terminals on the Motor-Shield.
Constructor Arguments
motor
The label of the relevant motor terminal (i.e. "MOTOR1", "MOTOR2", "MOTOR3", "MOTOR4")
config
An integer (1 or 2) defining which pin should be considered "forward" and which "reverse"
Methods
test(state)
Sets the Motor test mode on or off (takes a boolean argument). When on issuing a command to the motor terminal will illuminate the motor's related LED arrow rather than power the motor.
forward()
Starts the motor turning in its configured "forward" direction.
reverse()
Starts the motor turning in its configured "reverse" direction.
stop
Stops power to the motor
Examples
m1 = Motor("MOTOR1",1)
m1.forward()
LinkedMotors
This class describes a set of Motor objects and is used to group related motors together.
Constructor Arguments
*motors
List of Motor objects
Methods
forward()
Starts the linked motors turning in their configured "forward" direction.
reverse()
Starts the linked motors turning in their configured "forward" direction.
stop()
Stops power to the linked motors
Example
m1 = Motor("MOTOR1",1)
m2 = Motor("MOTOR2",2)
mtrs = LinkedMotors(m,m2)
mtrs.forward()
Sensor
This class describes the sensor connectors on the Motor-Shield
Constructor arguments
sensortype
string identifying which sensor is being configured. i.e. "IR1", "IR2", "ULTRASONIC"
boundary
An integer specifying the minimum distance (in centimeters) at which the sensor will return a Triggered response of True. This is only meaningful for the ultrasonic sensor.
Methods
trigger()
Executes the relevant routine that activates and takes a reading from the specified sensor. If the specified "boundary" has been breached the Sensor's Triggered attribute gets set to True.
Example
us = Sensor("ULTRASONIC",10)
us.trigger()
if us.Triggered:
print("Boundary breached")
ir1 = Sensor("IR1",0)
ir1.trigger()
if ir1.Triggered:
print("IR triggered")
Arrow
Class defining the arrow LEDs mounted on the Motor-Shield.
Constructor Arguments
which
An integer (1 - 4) representing an LED arrow. The arrow number if arbitrary starting with: 1 = Arrow closest to the Motorshield's power pins and running clockwise round the board ... 4 = Arrow closest to the motor pins.
Methods
on()
Turns on the LED arrow
off()
Turns off the LED arrow
Example
a1 = Arrow(1)
a1.on()