actuators - Working with Actuators¶
actuators module provides a collection of classes to interact with actuators, such as servos, relays, and buttons.
Allows control of a Grove Servo. Default
portfor the servo is
positionparameter sets the initial position of the servo.
degreeposition of the servo (between
180, which is half a circle). If
degreeis greater than 180, the servo will be set at the
180degree position. Likewise, if
degreeis less than
0, the servo will rotate to the 0 degree position.
Returns the current position of the servo in degrees.
from actuators import Servo s = Servo(1, init_degree = 180) # defines a servo connected to port 1 with initial position at 180 degrees. s.set_position(90) # rotate the servo by 90 degrees.
Allows control of a Grove Relay. The relay by default is normally open (NO) triggered by a
Activate the relay, close the circuit, and turn on whatever appliance that’s connected to the relay.
Deactivate the relay, open the circuit, and turn off whatever appliance that’s connected to the relay.
Trueif the relay is on, or
Falseif the relay is off.
Allows control of a Grove Buzzer. You can control the buzzer to play a note or a piece of music. The notes are written in strings. Available notes are
["c", "d", "e", "f", "g", "a", "b", "C", " "]. White space means skip.
Plays a note.
durationcontrols how long the note gets played.
play_music(notes, rhythms[=None], tempo[=1])¶
Plays a string of
notes. You may supply a list of numbers the same length as
rhythms, how long each note gets played. You may also specify an overall
tempo. The larger
tempois, the slower the music.
Using the buzzer
from actuators import Buzzer buzzer = Buzzer(port=2) # Plays one note buzzer.play_note("c", duration=1) # Plays a piece of music buzzer.play_music("cdefgabC", rhythms=[32, 16, 8, 4, 2, 1, 0.5, 1], tempo = 0.8)