When you're flying through space near light speed, you probably want to see what's coming up ahead. Turn on the Code Rocket's headlights for some assistance.
The code in the editor below already works. Just plug in your Code Rocket and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.
New Concept: Changing variable values
You’ve been using variables throughout your Code Rocket projects, but here, the variable value is changing based on a button press. The button press changes the variable value, then you use the ‘if’ statements to interpret that variable value. Is the variable equal to 1? If so, turn on the lights! If it’s anything else, turn off the lights and set the variable equal to zero.
Because the button affects the variable and the variable affects the action, you can create lots of different actions from just one button input to the code.