Optúil#
Réamhrá#
Is braiteoir bunaithe ar sholas é an Braiteoir Optúil a úsáideann solas frithchaite chun rudaí a bhrath, dathanna a aithint, agus gile agus dath a thomhas.
Is féidir leat gile sholas inmheánach an braiteora a chumrú freisin. Tá na huirlisí seo oiriúnach do chláir a gcaithfidh freagairt do rudaí daite, dálaí soilsithe, nó aiseolas braiteora i bhfíor-am.
Úsáideann an leathanach seo optical_1 mar ainm samplach don Braiteoir Optúil. Cuir d’ainm cumraithe féin ina áit de réir mar is gá.
Seo thíos liosta de na modhanna uile:
Gníomhartha — Cas LED an Braiteora Optúil air nó as.
set_light— Socraíonn sé staid ar siúl nó as an soilse LED.
Múiteoirí — Coigeartaigh gile LED agus socruithe braite réad.
set_light_power— Socraíonn sé gile an LED.object_detect_threshold— Socraíonn sé an tairseach chun réada a bhrath.
Faighteoirí — Léigh láithreacht, dath, gile, dath, RGB, agus stádas braiteora réada.
is_near_object— Tugann sé seo ar ais an bhfuil réad braite gar don Braiteoir Optúil.color— Tugann sé seo an dath is gaire a braitheadh a mheaitseálann an dath céanna ar ais.brightness— Tugann sé seo gile réada braite ar ais.hue— Tugann sé seo dath réada braite ar ais.rgb— Tugann sé seo ar ais na luachanna RGB a bhraith an Braiteoir Optúil.installed— Tugann sé seo ar ais an bhfuil Braiteoir Optúil ceangailte leis an Inchinn.
Glao ar ais — Rith cód nuair a bhraitear nó a chailltear réad.
object_detected— Cláraíonn sé feidhm le glaoch uirthi nuair a bhraitear réad.object_lost— Cláraíonn sé feidhm le glaoch uirthi nuair a chailltear réad.
Tógálaithe — Braiteoir Optúil a thosú agus a chumrú de láimh.
Optical— Cruthaíonn sé Braiteoir Optúil.
Gníomhartha#
set_light#
set_light Socraíonn LED an Braiteora Optúil go air, as, nó leibhéal gile socraithe.
Usage:
optical_1.set_light(state)
Paraiméadair |
Cur síos |
|---|---|
|
An staid chun an solas nó céatadán na cumhachta a shocrú sa raon 0 go 100. Is féidir leis an staid a bheith ar cheann acu seo a leanas:
|
# Turn the LED on and off forever
while True:
optical_1.set_light(LedStateType.ON)
wait(0.5, SECONDS)
optical_1.set_light(LedStateType.OFF)
wait(0.5, SECONDS)
# Turn the LED on and off forever
while True:
optical_1.set_light(100)
wait(0.5, SECONDS)
optical_1.set_light(0)
wait(0.5, SECONDS)
Sóiteoirí#
set_light_power#
Socraíonn set_light_power gile sholas an Braiteora Optúil. Mura bhfuil an LED lasta cheana féin, cuirfidh an modh seo an LED air freisin.
Usage:
optical_1.set_light_power(value)
Paraiméadair |
Cur síos |
|---|---|
|
An leibhéal cumhachta chun an solas a shocrú ó 0 go 100 mar chéatadán. |
# Turn the LED light on at different
# intensities
optical_1.set_light(LedStateType.ON)
wait(2, SECONDS)
optical_1.set_light_power(10)
wait(2, SECONDS)
optical_1.set_light_power(100)
object_detect_threshold#
Socraíonn object_detect_threshold an raon ónar féidir leis an braiteoir réada a bhrath. Tugann an modh seo an tairseach nua-socraithe ar ais freisin.
Léiríonn uimhreacha atá níos gaire do 255 raon níos lú, agus léiríonn uimhreacha atá níos gaire do 0 raon níos mó.
Usage:
optical_1.object_detect_threshold(value)
Paraiméadair |
Cur síos |
|---|---|
|
Uimhir sa raon 0 - 255. Ní thabharfaidh luach 0 ach an luach reatha ar ais. |
def detected():
# The Brain will print that an object was detected on
# the Brain's screen.
brain.screen.print("object detected")
brain.screen.next_row()
optical_1.object_detect_threshold(254)
optical_1.object_detected(detected_closer)
def detected_closer():
# Detect an object closer to the sensor.
brain.screen.print("Detected closer")
# Run detected when the Optical Sensor detects an object.
optical_1.object_detect_threshold(100)
optical_1.object_detected(detected)
# Detect an object first with the detect threshold at 100,
# then again at 254
stage = 0
def detected():
global stage
if stage == 0:
brain.screen.print("Get closer...")
brain.screen.next_row()
stage = 1
optical_1.object_detect_threshold(254)
optical_1.object_detected(detected_closer)
def detected_closer():
global stage
if stage == 1:
brain.screen.print("Too close!")
brain.screen.next_row()
stage = 2
optical_1.object_detect_threshold(100)
optical_1.object_detected(detected)
wait(15, MSEC)
Faighteoirí#
is_near_object#
is_near_object tugann sé seo ar ais an bhfuil an Braiteoir Optúil in aice le réad.
True— Tá an braiteoir gar do réad.False— Níl an braiteoir in aice le réad.
Usage:
optical_1.is_near_object()
Paraiméadair |
Cur síos |
|---|---|
Níl aon pharaiméadair ag an modh seo. |
# Stop driving when Optical Sensor is
# near an object
while True:
if optical_1.is_near_object():
drivetrain.stop()
else:
drivetrain.drive(FORWARD)
color#
Tugann color an dath réamhshainithe a bhraith an Braiteoir Optúil ó na dathanna thíos ar ais:
BLACKBLUECYANGREENORANGEPURPLEREDTRANSPARENTWHITEYELLOW
Usage:
optical_1.color()
Paraiméadair |
Cur síos |
|---|---|
Níl aon pharaiméadair ag an modh seo. |
# Stop the robot if the Optical Sensor
# detects red
while True:
if optical_1.color() == Color.RED:
drivetrain.stop()
else:
drivetrain.turn(RIGHT)
brightness#
Tugann brightness an gile a bhraith an Braiteoir Optúil ar ais.
Ciallaíonn céatadán níos airde go mbraitheann an Braiteoir Optúil níos mó solais. Ciallaíonn céatadán níos ísle go mbraitheann an Braiteoir Optúil níos lú solais.
Usage:
optical_1.brightness(readraw)
Paraiméadair |
Cur síos |
|---|---|
|
Roghnach. Luach Booleanach chun sonraí gile amha a léamh in ionad céatadáin:
|
hue#
Tugann hue luach an datha a bhraith an Braiteoir Optúil ar ais mar shnámhphointe sa raon ó 0 go 359.99 céim.
Is bealach é lí chun dath a chur síos trí uimhreacha a úsáid timpeall roth datha, mar a thaispeántar thíos.

Usage:
optical_1.hue()
Paraiméadair |
Cur síos |
|---|---|
Níl aon pharaiméadair ag an modh seo. |
# Check the hue of a detected object
# to determine if it is pink
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
if 290 < optical_1.hue() < 350:
brain.screen.print("Pink!")
wait(0.1,SECONDS)
else:
brain.screen.print("Not pink.")
wait(0.1,SECONDS)
rgb#
Tugann rgb na luachanna dearga, glasa, gorma agus gile a bhraith an Braiteoir Optúil ar ais mar Thupla.
Usage:
optical_1.rgb(raw)
Paraiméadair |
Cur síos |
|---|---|
|
Roghnach. Luach Booleánach chun a chinneadh an bhfuil luachanna amha nó próiseáilte á dtabhairt ar ais:
|
# Display the rgb values and brightness detected
# by the Optical Sensor.
brain.screen.set_font(FontType.MONO12)
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print(optical_1.rgb())
wait(0.1, SECONDS)
installed#
installed luach Booleach ar ais a léiríonn an bhfuil an Braiteoir Optúil ceangailte leis an Inchinn.
True— Tá an Braiteoir Optúil ceangailte leis an Inchinn.False— Níl an Braiteoir Optúil ceangailte leis an Inchinn.
Usage:
optical_1.installed()
Paraiméadair |
Cur síos |
|---|---|
Níl aon pharaiméadair ag an modh seo. |
# Display a message if the Optical Sensor
# is installed.
if optical_1.installed():
brain.screen.print("Installed!")
Glao ar ais#
object_detected#
object_detected feidhm athghlaoite nuair a bhraitear réad.
Usage:
optical_1.object_detected(callback, arg)
Paraiméadair |
Cur síos |
|---|---|
|
Feidhm [Feidhmeanna] atá sainmhínithe roimhe seo le forghníomhú nuair a bhraitear réad. |
|
Roghnach. Tupla ina bhfuil argóintí le cur chuig an bhfeidhm athghlaoite. Féach Feidhmeanna le Paraiméadair le haghaidh tuilleadh eolais. |
def detected():
drivetrain.stop()
brain.screen.set_cursor(1, 1)
brain.screen.print("object detected")
wait(0.5,SECONDS)
brain.screen.clear_screen()
# Display a message when the
# Optical Sensor detects an object
drivetrain.drive(FORWARD)
optical_1.object_detected(detected)
object_lost#
object_lost feidhm athghlaoite nuair a chailleann an Braiteoir Optúil réad braite.
Usage:
optical_1.object_lost(callback, arg)
Paraiméadair |
Cur síos |
|---|---|
|
Feidhm [Feidhmeanna] atá sainmhínithe roimhe seo le forghníomhú nuair a chailltear réad. |
|
Roghnach. Tupla ina bhfuil argóintí le cur chuig an bhfeidhm athghlaoite. Féach Feidhmeanna le Paraiméadair le haghaidh tuilleadh eolais. |
def lost():
drivetrain.stop()
brain.screen.set_cursor(1, 1)
brain.screen.print("object lost")
wait(0.5,SECONDS)
brain.screen.clear_screen()
# Display a message when the Optical
# Sensor loses sight of on object
drivetrain.drive(REVERSE)
optical_1.object_lost(lost)
Tógálaithe#
Úsáidtear tógálaithe chun Optical a chruthú de láimh, atá riachtanach chun Braiteoir Optúil a chumrú lasmuigh de VEXcode.
Optical#
Cruthaíonn Optical Braiteoir Optúil.
Usage:
Optical(smartport)
Paraiméadar |
Cur síos |
|---|---|
|
An Port Cliste a bhfuil an Braiteoir Optúil ceangailte leis, scríofa mar PORTx áit a seasann x d’uimhir an phoirt. |
# Construct an Optical Sensor "optical_1" with the
# Optical class
optical_1 = Optical(Ports.PORT1)
# Display the brightness of a red object detected
# by the Optical Sensor
drivetrain.turn(RIGHT)
while not optical_1.color() == Color.RED:
wait(50, MSEC)
drivetrain.stop()
brain.screen.print(optical_1.brightness())