Turn on a Rocket LED

Before any mission, it’s important to test each component of a space ship and ensure it’s working correctly. In these first few projects, you’ll learn how each component on Code Rocket works and how you can control them with code.

Code

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.

//Turn on LED 5 of your Code Rocket void setup(){ pinMode(5,OUTPUT); //Set the LED as an 'OUTPUT' } void loop(){ digitalWrite(5,HIGH); //turn on the LED with the HIGH command } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Videos

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!

Challenges

Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

Concepts

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: Getting Used to the Code Editor

When you're writing code, you need a program to do that, just like you need a program to write an essay. The code editor has the basic tools you need to write and upload your code.

If you look at the top bar of the code editor, the first button you see is "Restore." Clicking that button will erase all of your custom-written code and replace it with the example code that was in the code editor when you started. Use this button if you're lost or confused about an error you made, and you'd like to just start over with the example code. Beware! Once you click "Restore," your custom code is gone.

The second button is a drop-down menu for font size. Use this to help you see the details of your code by making the font bigger, or to see more lines of code by making the font smaller.

A drop-down menu in the middle of the code editor top bar shows you which port your Code Rocket is connected to on your computer. On Windows and Mac, this port should say ‘LSC Board’. On Chromebook, it will say something like /dev/tty.usbserial…. . If that port is empty, ensure that Code Car is plugged in and the power light is on. 

On the right-hand corner of the code editor, you have the "Upload" button. This button will send your code from the editor to your board. Make sure you press this button after each update to your code, or your code won't be running!

In the bottom right corner of the code editor, you'll see little messages that tell you the status of your code. After an upload, for example, there will be a message that says "Upload complete!"

If there is an error in your code when you press "Upload," you'll see red lines appear in the code editor. Scroll down just below the code editor to see the errors that the computer found and use those clues to fix the bugs!

 

New Concept: Syntax!

Syntax is the set of rules you use to structure your programs. Though it uses some different characters, code syntax works the same way that you use commas, periods, paragraphs and chapters to structure a book. Computer code is very picky about syntax, but luckily there are only a few key things to learn.

Semicolons usually end a single function. You'll see them at the end of most lines of code.

Parentheses usually hold the specific information that a function needs to run. For example, pinMode needs a pin number and a mode. Those two things are grouped together inside some parentheses.

Commas separate pieces of information. You can't use a comma in a big number like 1,500,000 because the computer will think you have three numbers: 1, 500, and 000.

Curly braces usually hold multiple commands. These are the big 'chunks' of code and they will often have commands inside of them so an opening curly brace and a closing curly brace are not usually on the same line. 

Syntax errors are the most common mistake when you're starting out. Don't be too frustrated by them, but instead pay close attention to the patterns of syntax and don't copy/paste or delete syntax if you're not sure where it came from.

Quiz

If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

1. Which syntax ends the entire 'void loop' function?




2. Which syntax ends a single code command?