Importing The Library
Import the library:
import Raspbot_Lib
Initialize a "bot" object.
bot = Raspbot_Lib.Raspbot()
Buzzer Control
The buzzer can be controlled using a boolean value.
# buzzer is on
bot.Ctrl_BEEP_Switch(0)
# buzzer is off
bot.Ctrl_BEEP_Switch(1)
Read Key Press
The robot has a button to the right of the reset button which can be read from.
state = bot.read_data_array(0x0d, 1)
state
will contain a boolean value, \(0\) if it's pressed and \(1\) if it's not pressed.
This reads from the 0x0d
register of the shield, which corresponds to the state of the key press of the button using the i2c protocol. To find out more about the different registers, the datasheet is linked here.
LED Bar Control
The robot is equipped with a long RGB bar at the back consisting of 10 RGB LED beads.
Simultaneous Control Of The Beads
To control all of the beads all at once, use the following methods:
state = 1 # turn LED off or on (0 or 1)
color = 1 # corresponds to the index of this list of color [Red, Green, Blue, Yellow, Purple, Indigo, White, Off]
bot.Ctrl_WQ2812_ALL(state, color)
The whole LED bar will light up in GREEN.
To use custom colors:
R=255 # R, G, B values range from 0 to 255
G=255
B=255
bot.Ctrl_WQ2812_brightness_ALL(R, G, B)
The whole LED bar will light up in WHITE.
Controlling The Beads Individually
To use preset colors
number = 5 # beads index number from 1 to 10
state = 1 # boolean value
color = 1 # corresponds to the index of this list of color [Red, Green, Blue, Yellow, Purple, Indigo, White, Off]
bot.Ctrl_WQ2812_Alone(number,state, color)
This will set LED number 5 (probably the LED at the end of the bar) to GREEN.
To set use custom colors:
number = 5 # beads index number from 1 to 10
R=255 # R, G, B values range from 0 to 255
G=255
B=255
bot.Ctrl_WQ2812_brightness_Alone(number, R, G, B)
This will set LED number 5 (probably the LED at the end of the bar) to WHITE.
Using LightShow
Class
The built in LightShow
class has preset effects.
Initialize an object.
lights = Raspbot_Lib.LightShow()
To use preset effects, use the execute_effect
method
# effects include ['river', 'breathing', 'gradient', 'random_running', 'starlight']
effect_name = "river"
effect_duration = 15 # in seconds
speed = 0.01 # pause every 0.1 seconds
current_color = 1 # only matter for "breathing" effect
# corresponds to the index of this list of color [Red, Green, Blue, Yellow, Purple, Indigo, White, Off]
lights.execute_effect(effect_name,effect_duration,speed,current_color)
Servo Control
The robot comes equiped with 2 servo to control the angles of the camera. - Servo 1 (from \(0^\circ\) to \(180^\circ\)) controls the yaw (rotates along the x-y plane, around the z-axis) - Servo 2 (from \(0^\circ\) to \(110^\circ\)) controls the pitch (rotates along the y-z plane, around the x-axis)
servo_id = 1
servo_angle = 60
bot.Ctrl_Servo(servo_id, servo_angle)
Reading From IR remote
The robot is capable of receiving IR signals from a IR transmitter or a remote. From the following datasheet, its register is at 0x0C
.
Turn on the IR remote
bot.Ctrl_IR_Switch(1)
Read data
reg = 0x0C
desired_block_length = 1
output = bot.read_data_array(reg, desired_block_length)
Note: when it's not in use, it's best to turn off the IR remote.
Turn off the IR remote
bot.Ctrl_IR_Switch(0)
Additional Info
- When no button is pressed, the output will be
0xFF
- For Yahboom remote control, the keys range from
0x00
to0x1a