Let’s start with basics- beep a single tone on speaker on repeat to learn about loops!
The code in the editor below already works Just plug in your Code Speaker 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 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!
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: Loops
Computers are great at doing things over, and over, and over, and over again. That’s what happens inside your void loop() function in this program. The computer reads your program from top to bottom, so it reads line 8 before line 9. However, it’s reading really fast, so you’ll usually have to add in some delay to make sure you can see how your program is working.
As you program more, you’ll get better at imagining which line of code is running as you watch your program work on Code Speaker. You might even start to think of the program more as a ‘circle’ than a single sheet of code.
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.