Before coding, let's get familiar with the IDE. Here is some vocabulary and where to find the different parts.
We will show you:
|
This is a video of IDE basicsIf you are doing this on your own at home, this video teaches you what we did in class.
|
|
Lesson 1: Learn How to Code!We will start with writing simple code, saving, and sending it to the Arduino. Let's start by getting the board's orange light to blink like this.
|
|
If you got an error message, check the following things.
1) Are all the colored parts in this picture here colored in your code? 2) Check CaPiTaL letters. (they matter) 3) Have you forgotten a ; 4) You may have forgotten a ( or ) 5) Are there curly brackets, { } If you get no error (the bottom box is not orange), then you can move on. Still having issues? Let your teacher know! |
The // double dashes are just comments. You do not need to type them. The Arduino does not do anything with them. They they help people know what each line of code is supposed to do.
Remember, this video shows what the Arduino should be doing. |
|
SaveNow that you have made your first successful code, you should save it.
Name it something memorable so you can always find it again later. Your teacher will show you how, or you can watch this video. |
|
It is important to know LEDs only let current flow through it one way.
If your light does not turn on, try flipping how your LED is connected. It may just be in backwards. |
LEDs only work when the longer end connects to positive pins on the board. The + pins on the board are any of the numbered pins, the 3V, or the 5V.
|
<--Use this button to learn how |
LEDs are Light Emitting Diodes. Light Emitting means they make light. A diode is something that only lets electric current go one way. That means direction matters! The longer LED wire is the + side, and the shorter LED wire is the - side.
Tip: use black wires to connect - parts (aka GND) and red wires to connect + parts (aka 3.3 or 5V lines) See how that is done in the pictures above? |
Here is the example multi-blink code from earlier. See how we have to keep typing LED_BUILTIN over and over? We can avoid that by making what is called a "variable". Variables are easily able to be adapted/changed. If you have taken algebra, think solving for x, where x is the variable!
What if we wanted to change which light to turn on? We would then have to then retype all of the LED_BUILTIN parts, gross! If we make a variable for the light at the start of our code? Then we will only have to change the pin we want to light up in just one spot! |
See this small change we added to the beginning of our code, line 1?
This is the variable we are defining. Const means constant. That means we are telling the computer that this variable will not be changing when the code runs. int means integer. An integer means whole numbers. Integers are numbers like 1, 5, 22, etc. LED_BUILTIN is actually connected to Arduino pin 13, so we could have just typed in 13 there if we wanted. |
Look on the rail of your Arduino. Some of the holes digital row have a ~ symbol in front of them. If you look at this picture, the ~ means PWM. That means Pulse Width Modulation. Modulation means it can modulate up and down from various values. The digitalWrite we used before just uses on and off. If you move your wiring to use one of these ~ pins, like ~3, we can make it blink with different brightness.
|