spikedev.sensor¶
A module to interact with the color
, distance
, and touch
sensors
Example¶
from spikedev.sensor import ColorSensor, TouchSensor
cs = ColorSensor()
ts = TouchSensor()
# when the user presses the TouchSensor, read the RGB values from the ColorSensor
ts.wait_for_bump()
print("color sensor RGB values are {}".format(cs.rgb()))
Classes¶
-
class
spikedev.sensor.
Sensor
(port, desc=None)¶ Bases:
object
- Parameters
port (hub.port) – the hub.port.X for this sensor
desc (str) – description, defaults to None
-
set_mode
(mode)¶ Set the mode for the sensor to
mode
-
value
()¶ Return the current value(s) from the sensor
-
class
spikedev.sensor.
TouchSensorMode
¶ Bases:
object
FORCE
value will be from 0 to 10TOUCH
value will be either 0 or 1TAP
value is one of None, 1, 2 or 3FPEAK
value will be from 0 to 10, remembers the highest valueFRAW
value will be from 380 to 698FPRAW
TBDCALIB
TBD
-
FORCE
= 0¶
-
TOUCH
= 1¶
-
TAP
= 2¶
-
FPEAK
= 3¶
-
FRAW
= 4¶
-
FPRAW
= 5¶
-
CALIB
= 6¶
-
class
spikedev.sensor.
TouchSensor
(port, desc=None, mode=1)¶ Bases:
spikedev.sensor.Sensor
-
value
()¶ Return the current value of the
TouchSensor
-
is_pressed
()¶ Set the mode to
TouchSensorMode.TOUCH
. ReturnTrue
if the TouchSensor is currently pressed, else returnFalse
-
is_released
()¶ Set the mode to
TouchSensorMode.TOUCH
. ReturnTrue
if the TouchSensor is currently released, else returnFalse
-
wait_for_pressed
(timeout_ms=None)¶ Wait
timeout_ms
for theTouchSensor
to be pressed. ReturnTrue
if the button was pressed withintimeout_ms
, else returnFalse
. Iftimeout_ms
isNone
this will wait for forever.
-
wait_for_released
(timeout_ms=None)¶ Wait
timeout_ms
for theTouchSensor
to be released. ReturnTrue
if the button was released withintimeout_ms
, else returnFalse
. Iftimeout_ms
isNone
this will wait for forever.
-
wait_for_bump
(timeout_ms=None)¶ Wait
timeout_ms
for theTouchSensor
to be bumped. ReturnTrue
if the button was bumped withintimeout_ms
, else returnFalse
. Iftimeout_ms
isNone
this will wait for forever.
-
-
class
spikedev.sensor.
ColorSensorMode
¶ Bases:
object
COLOR
single value, LED is onREFLT
single value, LED is on, 0 - 100AMBI
single value, LED is off, 0 - 100LIGHT
three values, LED is off, always reads [0, 0, 0], not sure?RREFL
two values, LED is on, not sure?RGB_I
four values, LED is on, (red, green, blue, intensity?)HSV
three values, LED is on, (hue, saturation, value)SHSV
four values, LED is off, not sure?DEBUG
TBDCALIB
TBD
-
COLOR
= 0¶
-
REFLT
= 1¶
-
AMBI
= 2¶
-
LIGHT
= 3¶
-
RREFL
= 4¶
-
RGB_I
= 5¶
-
HSV
= 6¶
-
SHSV
= 7¶
-
DEBUG
= 8¶
-
CALIB
= 9¶
-
class
spikedev.sensor.
ColorSensor
(port, desc=None, mode=0)¶ Bases:
spikedev.sensor.Sensor
-
color
()¶ The number of the color. The LED is on.
-
reflected_light_intensity
()¶ Set the mode to
ColorSensorMode.REFLT
and return the reflected light intensity as a percentage (0 to 100). The LED is on.
-
ambient_light_intensity
()¶ Set the mode to
ColorSensorMode.AMBI
and return the ambient light intensity as a percentage (0 to 100). The LED is off.
-
hsv
()¶ Set the mode to
ColorSensorMode.HSR
and return the Hue, Saturation, Value values. The LED is on.
-
rgb
(scale_by_intensity=True)¶ Set the mode to
ColorSensorMode.RGB_I
and return the Red, Green, Blue values. The LED is on.
-
-
class
spikedev.sensor.
DistanceSensorMode
¶ Bases:
object
DISTL
returns a number from 4 to 49DISTS
returns a number from 4 to 24. Does not work from as far away as DISTLSINGL
always returns [18]LISTN
always returns [0]TRAW
returns a number between 80 and 1600LIGHT
always returns [0, 0, 0, 0]PING
always returns [None]ADRAW
always returns [20]CALIB
TBD
-
DISTL
= 0¶
-
DISTS
= 1¶
-
SINGL
= 2¶
-
LISTN
= 3¶
-
TRAW
= 4¶
-
LIGHT
= 5¶
-
PING
= 6¶
-
ADRAW
= 7¶
-
CALIB
= 8¶
-
class
spikedev.sensor.
DistanceSensor
(port, desc=None, mode=0)¶ Bases:
spikedev.sensor.Sensor