mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 09:37:25 +00:00
These code samples are rendered in the docs, so we include them here. For the git history of these snippets, see: https://github.com/pybricks/pybricks-projects/commits/f4914069aaacfd9ab1e0dd6f05524f62cfc56b29/snippets
20 lines
457 B
Python
20 lines
457 B
Python
#!/usr/bin/env pybricks-micropython
|
|
from pybricks.parameters import Port
|
|
from pybricks.tools import wait
|
|
from pybricks.iodevices import Ev3devSensor
|
|
|
|
# Initialize an Ev3devSensor.
|
|
# In this example we use the
|
|
# LEGO MINDSTORMS EV3 Color Sensor.
|
|
sensor = Ev3devSensor(Port.S3)
|
|
|
|
while True:
|
|
# Read the raw RGB values
|
|
r, g, b = sensor.read('RGB-RAW')
|
|
|
|
# Print results
|
|
print('R: {0}\t G: {1}\t B: {2}'.format(r, g, b))
|
|
|
|
# Wait
|
|
wait(200)
|