07 Quick Start


Your mission is to create a robot that counts how many times the lights are turned off and on in a day.


This mission is not about whether the lights are on or off. It is about counting how many times the lights change from on to off and back again.

Start by drawing out a state diagram to help you make sense of the program you're about to write.  It should include space for:

            • Lights are on and stay on
            • Lights are on and turn off
            • Lights are off and stay off
            • Lights are off and turn on


Then plug the Light and Color Sensor into an I2C port, and the LED into an AD port.

Code: Initialize the Variables

Create three variables. One for "count", one for "state" and one for "threshold".

Code: State Machine

While you set up your state machine (measuring different states as measured by different thresholds), use the print function to check your work!

Code: LED Reporting

Now add commands for the LED alongside the print functions.  Get creative - you can use commands that set the LEDs to different brightnesses and for different lengths of time!


Test your robot by turning the lights on and off several times in your environment. Does your robot report the correct number of changes?


Time to get creative! You might enjoy adding other actuators that you've received throughout your GoBox experience!

Last modified: Monday, 28 November 2022, 10:30 AM