Park in the Dark
The project halt_under_shadow will make the cyber:bot go forward until the phototransistor detects a shadow that’s dark enough to make the voltage applied to D/A2 drop below 0.1 V, or a different threshold you choose.
- Use the micro:bit Makcode Editor to open a project that already has the cyber:bot extension, like phototransistor_voltage or cyberbot-template-with-blink.
- Set the name to halt_under_shadow, and enter the project below over the existing project.
- Using the measurements you just took with the project phototransistor_voltage, update the threshold value 0.1 in if (volts < 0.1) with a value consistent with “shade” in your ambient lighting.
- Click Download.
- Place your cyber:bot on the floor in ambient light, pointing straight towards the cardboard box “garage” or other dark spot.
- Move the power switch to position 2 so the cyber:bot will drive forward. How close did it get to stopping directly in the box-garage?
- If needed, try making adjustments to the threshold you set in the if (volts <…) statement to get the cyber:bot to stop directly in the box garage.