Pages

Sunday, March 8, 2015

Arduinos: Day 1

In class this past Tuesday we started our new unit: Feedback and Control. For this unit I will be working with Sarah Barden on whose blog you can also follow for our progress. 

A main component of this unit will be working with Arduinos. To become more familiar with how they work, today we practiced using them to control LEDs. 

Arduinos and "Blink" Program

Using the Blink we first learned how to run and modify a program. We started with the example Blink program provided on Arduino (seen below), and then proceeded to modify the delay between when the LED located on the Arduino board turned on and off. 


Once we understood how the Blink program worked, we then learned how to set up a circuit board by attaching an additional LED and including it in the above code. Our new LED was connected to Pin 12 and grounded through a resistor connected back to the Arduino board. After playing with a couple different delay patterns between LED 12 and 13 we settled on the one seen below. This pattern has LED 13 blinking once for 500ms, then LED 12 blinking once for 500ms, and then three more times quickly before LED 13 turns on again. 




We also practiced using the Blink program using four LEDs attached to the circuit board. The modified program we created below causes the first light (LED 2) to turn on and off, followed by the second one (LED 4), then the third one (LED 7), and finally the fourth one (LED 12) before traveling back down the line.


Arduinos and "Blink Without Delay" Program

The Blink Without Delay program (code seen below) allows the arduino to do two or more things at once. In the context of using LEDs, this program turns on the LED on and then makes note of the time to then check and see if the desired blink time has passed before turning it on or off again. 

  
The last part of what we did today was understanding this program and use it to create a pattern with the 4 LEDs we had set up earlier. In the program we used else if statements to control when each individual LED would turn on and off so that only one LED was off at a time. What we came up with can be seen below.

                


Reflection

Today as my first formal experience with coding. I think it is very handy that the Arduinos have so many well annotated example codes. It made it much easier to understand what the original codes were doing before altering them. It was still challenging, however, to use the blink without delay program, as we had to take into account the LEDs relationship to each other within the code. 

1 comment:

  1. Nice work on the codes! it was really helpful that you commented so thoroughly. As a person with very little experience with code, It really helped me to follow what the code was trying to communicate. Also, great job with the pattern! it looks like a mini light show!:)

    ReplyDelete