In word blocks, there is a quite big difference of how sensors behave as those azure sensors blocks, compared to yellow events blocks. When you are using them as events trigger, sensor will not retriger the event, until the sensor values changes to falsy and then back to truthy. In sensor block variant, if sensor stays true in for example while loop
, it will keep triggering the event indefinitely.
In pythonBlocks, you can achieve both behaviors, but here we are going to cover the 'sensor block' variants.
- color sensor is
- color sensor (value)
- color sensor reflection is
- color sensor reflection (value)
- color sensor RGBI
- force sensor is
- prassure in
- distance sensor is
- distance sensor (value)
- is tilted
- when is up
- when gesture is
- gesture (value)
- angle (value)
- set yaw angle to 0
- acceleration (value)
- angular velocity (value)
- set sensor orientation to
- orientation (value)
- is button pressed
- timer (value)
- reset timer
color_sensor.color(port.A) == color.RED
usage:
if color_sensor.color(port.A) == color.RED:
pass #your code here
color_sensor.color(port.A)
usage:
color_variable = color_sensor.color(port.A)
color_sensor.reflection(port.A) < 50
- You can use any comparison operator comparison operator here.
- Value is in range 0 (black, no light reflected) to 100 (white, all light reflected).
color_sensor.reflection(port.A)
There is one more mode, that is not present in word blocks, and that is RGBI mode:
color_sensor.rgbi(port.A)
which returns tuple [red: int, green: int, blue: int, intensity: int]
. So, if you want just red
value, you can do:
color_sensor.rgbi(port.A)[0]
force_sensor.pressed(port.A) == 1
force_sensor.pressed(port.A) == 0
force_sensor.force(port.A) > 50
force_sensor.force(port.A)
round(force_sensor.force(port.A) / 10)
percentage:
_distanceSensor.distance_percentage(port.A) < 15
cm:
_distanceSensor.distance_cm(port.A) < 15
inch:
_distanceSensor.distance_inch(port.A) < 15
percentage:
_distanceSensor.distance_percentage(port.A) > 15
cm:
_distanceSensor.distance_cm(port.A) > 15
inch:
_distanceSensor.distance_inch(port.A) > 15
percentage:
_distanceSensor.distance_percentage(port.A) == 15
cm:
_distanceSensor.distance_cm(port.A) == 15
inch:
_distanceSensor.distance_inch(port.A) == 15
_distanceSensor.distance_percentage(port.A)
_distanceSensor.distance_cm(port.A)
_distanceSensor.distance_inch(port.A)
distanceSensor.distance(port.A)
_motion_sensor.tilt_angles(1) > 130
_motion_sensor.tilt_angles(1) < -130
_motion_sensor.tilt_angles(2) > 130
_motion_sensor.tilt_angles(2) < -130
_motion_sensor.tilted(0) == True
_motion_sensor.tilted(0) == False
note: basically, this is the same as when tilted *somewhere*
, but breakpoint value is in the middle, which is 450
out of 900
instead of 130
. There is one more option, not covered by when tilted
which is when bottom is up
, which you can implement like this:
_motion_sensor.upside_down(0) == True
motion_sensor.gesture() = motion_sensor.SHAKEN
other possible values are: motion_sensor.TAPPED
, motion_sensor.DOUBLE_TAPPED
, motion_sensor.FALLING
and motion_sensor.UNKNOWN
which corresponds to 'no gesture'
motion_sensor.gesture()
_motion_sensor.tilt_angles(1)
_motion_sensor.tilt_angles(2)
_motion_sensor.tilt_angles(0)
motion_sensor.reset_yaw(0)
motion_sensor.acceleration(False) # tuple of 3 values
motion_sensor.acceleration(False)[0] # x value
motion_sensor.acceleration(False)[1] # y value
motion_sensor.acceleration(False)[2] # z value
pass True
as argument to get acceleration as raw, unfiltred values
motion_sensor.angular_velocity(False) # tuple of 3 values
motion_sensor.angular_velocity(False)[0] # x value
motion_sensor.angular_velocity(False)[1] # y value
motion_sensor.angular_velocity(False)[2] # z value
pass True
as argument to get angular velocity as raw, unfiltred values
motion_sensor.set_yaw_face(motion_sensor.FRONT)
possible values are: motion_sensor.FRONT
, motion_sensor.BACK
, motion_sensor.LEFT
, motion_sensor.RIGHT
, motion_sensor.TOP
and motion_sensor.BOTTOM
motion_sensor.get_yaw_face()
pressed:
button.pressed(button.LEFT) > 0
released:
button.pressed(button.LEFT) == 0
pressed:
button.pressed(button.RIGHT) > 0
released:
button.pressed(button.RIGHT) == 0
returns time in milliseconds (in word blocks it is in seconds)
timer.get_time_ms()
timer.reset_timer()