botcore
– CodeBot CB2 hardware interface¶
Core low-level module for CodeBot-CB2.
- The botcore module gives you direct access to all the hardware on the CodeBot CB2.
-
class
botcore.
Buttons
[source]¶ Access to pushbutton switches BTN-0 and BTN-1.
-
class
botcore.
CB_LEDs
[source]¶ Manage all the LEDs on CodeBot.
-
enc_emit
(b)[source]¶ Set both Encoder emitter LEDs (2-bit value).
- Parameters
b (int) – Binary value, 0=off, 1=left, 2=right, 3=both
-
ls
(b)[source]¶ Set all User Line Sensor marker LEDs to the given binary integer value, or list/tuple of bools.
- Parameters
b – int value used to set LEDs, from 0 to 31 (2 5-1), or
b – list of 5 bools. (see
botcore.CB_LEDs.user
for example)
-
prox
(b)[source]¶ Set both Proximity marker LEDs.
- Parameters
b – int binary value, 0=off, 1=left, 2=right, 3=both ; or,
b – list of 2 bools. (see
botcore.CB_LEDs.user
for example)
-
user
(b)[source]¶ Set all User Byte LEDs to the given binary integer value or list/tuple of bools.
- Parameters
b – int value used to set LEDs, from 0 to 255 (2 8-1) ; or,
b – list of 8 bools.
Example:
leds.user(0) # turn all User LEDs off leds.user(255) # turn all User LEDs on leds.user(0b10101010) # Alternating LEDs leds.user( [True, False, False, True, True, True, True, True] )
-
-
class
botcore.
Encoders
(leds)[source]¶ Manage the wheel encoders. This class demonstrates simple low-level sensing of encoders via ADC channels. Higher performance implementations are available in separate modules, such as
timed_encoders
.
-
class
botcore.
LineSensors
(leds)[source]¶ Manage the line sensors.
-
check
(thresh=1000, is_reflective=False)[source]¶ Fast check of all line sensors against threshold(s). Controls emitter also.
Return a tuple of values for all line sensors. By default these are bool values indicating presence of a line, based on given parameters. See below for alternate behavior based on parameter types.
- Parameters
- Returns
Collection of bool “line detected” values.
If thresh=0, returns raw ADC values (ints).
If is_reflective is an int value it is interpreted as thresh_upper, and the function returns -1,0,+1 for readings below/within/above thresholds.
- Return type
tuple [5]
-
-
class
botcore.
Motors
[source]¶ Manage the Motors
-
class
botcore.
Proximity
(leds)[source]¶ Manage the proximity sensors
-
range
(samples=4, power=1, rng_low=0, rng_high=100)[source]¶ Scan proximity sensors and return 0-100% range for each. This function runs a successive approximation algorithm to find the minimum range at which an object is detected by each sensor independently.
- Parameters
- Returns
0-100 if object detected, or -1 if not.
If samples=1, returns bool (L, R) values.
Note: When samples=1 the rng_high value is not used. A single sample is taken at rng_low.
- Return type
tuple of (L, R) int proximity values
-
-
class
botcore.
Speaker
[source]¶ Control the Speaker
-
pitch
(freq, duty=50)[source]¶ Play a tone on the speaker, with the specified frequency and duty-cycle.
This function produces a simple Square wave to drive the speaker.
-