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.
Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!
Can you complete the challenges? Change the code in the editor above, then upload it to your Code Rocket and see if you got the result. Don't stop here, keep experimenting with the code!
These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.
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.