Thames & Kosmos Robotics Workshop handleiding
Handleiding
Je bekijkt pagina 38 van 68

PROGRAMMING
SAMPLE PROGRAM FOR THE LIGHT-TRACKING ROBOT
The light-tracking robot uses a light sensor and motor to rotate towards a light source such as a flashlight. Test out
the program by holding a light source a few inches to the right or left of the light sensor. Watch as the robot rotates
toward the light source then stops once it is pointing toward it. This program is preloaded in the app in the Load Demo
Code menu. After testing out this program, try modifying it so that the light-tracking robot rotates away from the
source of light.
The first part of the code is placed in a loop so that the light-tracking robot is always checking to see if the reading from
the light sensor is greater than 900. Once that value is greater than 900, the program exits the loop.
The program uses an if-statement to compare the first (“a”) and
second (“b”) readings from the light sensor.
If the first reading is greater than or equal to the second reading,
that means the robot rotated away from the light source. So, the
robot rotates in the opposite direction (counterclockwise).
The light-tracking robot then turns on motor 1, rotating
the robot to the right.
This part of the code saves the initial value from the
light sensor as the variable “a.”
If the first reading is less than the second reading, that means the robot
rotated toward the light source. So, the robot rotates again in the same
direction that it initially rotated (clockwise).
The loop then repeats again, from the beginning, until the value from
the light sensor is greater than 900.
The robot then saves the second value as the
variable “b.”
Once the value from the light sensor is greater than
900, motors 1 and 2 are turned off.
Scan this QR code to view
online tech support videos
of the models in action.
36
Bekijk gratis de handleiding van Thames & Kosmos Robotics Workshop, stel vragen en lees de antwoorden op veelvoorkomende problemen, of gebruik onze assistent om sneller informatie in de handleiding te vinden of uitleg te krijgen over specifieke functies.
Productinformatie
Merk | Thames & Kosmos |
Model | Robotics Workshop |
Categorie | Niet gecategoriseerd |
Taal | Nederlands |
Grootte | 55434 MB |