What else can you make?
- play my favorite music
- use headlights in the dark
- use windshield wipers in the rain
- turn on the AC when it is hot
- park in a parking lot
Your parents do a lot of things when they drive, and our self-driving cars will need to do these things too. For this lesson we will be turning the headlights on and off!
(An LED is a kind of light. You have seen the RobotLAB autonomous car light up with many LEDs.)
Time to code!
|1. Bluetooth||2. Orchestra||3. Scratch|
Connect your autonomous car to your dedicated computer via Bluetooth.
Open Orchestra and connect your robot to the program.
Open Scratch from Orchestra
Write some code that makes your car turn on its lights if the brightness in the room goes below 30.
Look at this code from the first lesson.
Notice how the code you just saw is very similar. The blocks on the left turn the front lights on, and the blocks on the right turn the front lights off.
How can you tell if it is dark outside? You can see it with your eyes! How can your RobotLAB Autonomous Car tell if it’s dark?
Using a sensor called a CDS sensor.
Write some code that makes your car turn on its lights if the brightness in the room goes below 30 (make it a variable). Here are some blocks you can choose from:
It's much easier to troubleshoot your code when you can see the results from the sensor. But how can you log the value or make any sense of it if it's constantly changing?
- make several variables
- write the values down
- make a list in Scratch
- I don't know
1. Click "Make a List"
2. Name it something like "light" or "light data"
3. All these new blocks will appear!
4. And you'll see an empty list in the top left corner of the screen.
- Make your list save the current value from the CDS sensor every half second.
- Write a function that deletes all the list data when the space key is pressed.
Don’t worry, this isn’t for a grade, it’s just so your teacher can check the classes’ understanding.
- CDS sensor
- If loop
- Forever loop