botservices
– CodeBot event loop¶
Event-driven Services for CodeBot.
The module provides the BotServices
object, which lets you connect callback functions
to react to events.
Example of hooking a callback function:
from botservices import BotServices
bot = BotServices()
# Define callback function
def handle_button(buttons):
if buttons[0]:
# Do something amazing when BTN-0 is pressed!
# Hook the callback.
bot.on_button(handle_button)
-
class
botservices.
BotServices
[source]¶ CodeBot event loop built on
botcore
module.-
clear_last
()[source]¶ Clear last-value for all sensors, forcing event callbacks on next poll with new current values
-
on_accel
(cb)[source]¶ Attach callback to Accelerometer events.
- Parameters
cb – Callback function to be called when event happens. The function will be called with a single parameter, a
list
of 3 bools corresponding to X, Y, Z axes of acceleration.
Attach callback to Button Press events.
- Parameters
cb – Callback function to be called when event happens. The function will be called with a single parameter, a
list
of 2 bools.
-
on_line
(cb)[source]¶ Attach callback to Line Sensor events.
- Parameters
cb – Callback function to be called when event happens. The function will be called with a single parameter, a
list
of 5 bools.
-
on_prox
(cb)[source]¶ Attach callback to Proximity Sensor events.
- Parameters
cb – Callback function to be called when event happens. The function will be called with a single parameter, a
list
of 2 bools.
-
on_timeout
(cb, timeout_ms, arg=None)[source]¶ Schedule callback to occur after specified timeout.
- Parameters
cb – Callback function to be called after time period expires. Note: For a repeating timer, the callback function can use this function to re-register itself.
timeout_ms (int) – Timeout in milliseconds, after which callback will be called.
arg – Optional argument that will be passed to callback function
cb(arg)
.
-