This week, we started to work with Arduino, a program on which we can write codes to control an Arduino board with various inputs and outputs.
First, we started with a small light as the output, on pin 13 of the Arduino board.
The example program "Blink" programs the light to blink on and off at regular intervals. We modified the code so that there is no delay between the light turning on and off. We did this by adjusting the number of milliseconds that the program delays for -- from 1000 to 0.
This caused the light to blink on and off so quickly that to us, it just seemed like it was constantly on -- as our eyes cannot pick up something with that high of a frequency.
The next step was to create a pattern with the blinking light. We did this by adjusting the two delay intervals: we made the delay for 2000ms and the second delay for 500ms, so that the light would turn on for 2 secs and off for 0.5 secs.
The next step was to create a pattern with the blinking light. We did this by adjusting the two delay intervals: we made the delay for 2000ms and the second delay for 500ms, so that the light would turn on for 2 secs and off for 0.5 secs.
Then, we added an LED light on pin 12. We had to define the second light as an output, using digitalWrite, as shown below. And, we added the code for the pin 12 LED to blink into the loop. This time, the delay for turning off the lights was only 100ms, so the lights stayed on longer than they stayed off.
Following that, we added 3 more LED lights to pins 8, 7 and 4. The 3 pins were defined as outputs and the code from the previous program was repeated for the 3 new outputs. With this code, the 4 lights blinked one by one.
Another example program, "BlinkWithoutDelay", allows for the board to control multiple outputs at the same time without having to use the 'delay' command after every action. With fewer lines in the code, the program takes up less memory.
Our objective was to control the 4 LED lights from the previous code, but this time using "BlinkWithoutDelay" instead of "Blink".
First, we defined the 4 LEDs as pins 12, 8, 7, and 4, and the starting position for all of them as LOW -- or off.
Then we set the interval for the LED blinking at 100ms and set the 4 digital pins as the outputs.
Jumping right into Arduino programming was very difficult, but it is the kind of skill that is learned through experience. I noticed two importance technical aspects that we need to be careful on: one, is that the number of brackets matter - if the number of open and closed brackets don't match, the program will not compile; and two, the semi colons after each line of the commands is very important.
You pattern was so cool! How did you figure out what you wanted your pattern to be?
ReplyDelete