Lesson 13: Read the colours
Colours carry messages
- A colour on the floor can be a message for the robot: a parcel label, a road sign, a place to stop.
down_eye.detect(RED)isTruewhile the robot stands on red. It knows RED, GREEN, BLUE and BLACK.- The eye only sees the floor under the robot now. To use a colour later, keep it in a variable.
Words for this lesson
| Word | Meaning |
|---|---|
| label | a small sign on a parcel that says where it goes |
| bay | a marked place where a robot puts things down |
| variable | a name that remembers a value, like colour = "red" |
| sign | a picture or colour that tells you what to do |
| arrive | get to the place you wanted to go to |
Remember what you saw
from vexcode_vr import *
def main():
colour = "none"
if down_eye.detect(RED):
colour = "red"
drivetrain.drive_for(FORWARD, 500, MM)
brain.print("I started on: " + colour)
vr_thread(main)
colourgets its value at the start. After the drive the robot still knows it, even though the floor under it has changed.==asks "is it the same?":if colour == "red":isTrueonly whencolourholds"red".
Сложность 3/5 · 200 монет + небольшой бонус за первое завершение сегодня
The post robot stands on a parcel with a colour label: red, green or blue. Take the parcel to the bay of the same colour. Read the label first and keep it in a variable, because the eye cannot see it any more once the robot moves. Route: 1000 mm up; for red turn left, drive 600 mm, turn right; for blue do the same to the right; then 500 mm up into the bay.
Нажмите Запустить, чтобы увидеть результат здесь.
Сложность 3/5 · 200 монет + небольшой бонус за первое завершение сегодня
Coloured signs on the floor show the way. Red means turn left, blue means turn right, green means stop: you have arrived. Drive one square (250 mm) at a time and look at the floor in every square. Each map has a different route.
Нажмите Запустить, чтобы увидеть результат здесь.