Introduction to Arduino Programming (Nina Kowalke)

Reflection

This week we practiced programming the Arduino micro-controller.  I have had very limited experience with the Arduino prior to this week’s activities and so I made significant advances in my knowledge of Arduino programming.  As I am learning how to write code, it feels like I’m accessing a whole part of my brain that I never knew was there.  The way programming causes me to think is so different from any other subject in school and so I am fascinated by it.  I think what I like most is that programming seems to work my brain in a way similar to math which is a subject I really enjoy.  The main points I learned through this weeks exercises were as follows:  (1) How to form for-loops, (2) overall placement of pieces of code, and (3) how to troubleshoot when compiling has errors.

(1) I was familiar with the concept of for-loops going into these activities, however, I had not actually used them until this week.  I learned through this lab the true practicality of for-loops which is that they eliminate the need to copy and paste chunks of code repetitively.  This was especially helpful in this week’s activity when trying to turn on all 5 LEDs and then have them blink at various speeds.  Rather than copy and pasting the digitalWrite for each pin, the for-loop allowed us to create a format for performing actions on all LEDs at once.

(2) Similarly to for-loops, I would say I was familiar with Arduino coding placement before starting these activities, however, once I tried to start the activity I realized how much I had to learn.  I knew what the setup portion and the loop portion of the code were for, but deciding where to start when writing my own code and also what to include in the code was more daunting than I expected.  I now have a better grasp on how to start writing code and some of the important components.  Defining the variables seems to be the best place to start and some of the important components of the code which I discovered were the debounce library, stating the pinModes, and (in this case) a buttonState.

(3) This week’s activities also taught me about how to troubleshoot when my code is having errors compiling.  I still struggle with troubleshooting, but these activities definitely helped me to improve my mindset.  I now expect troubleshooting errors and so I don’t feel as discouraged when they arise and I learned how to better interpret the errors.  The errors are written in a strange format and so at first I had a hard time figuring out what they were saying, however, they make more sense to me now and I improved my ability to read them and interpret what might solve the error.  I’ve also improved my knowledge of what errors are common that I can check for each time.  These common errors would be semi-colons and brackets.  As I strengthen my ability to code, my ability to troubleshoot also increases.

Documentation

The class activities which I was able to learn the preceding lessons through involved looking at an LED behavior and then recreating that behavior by writing Arduino code which we then uploaded to the Arduino and a connected LED circuit on a breadboard.  This is what the set up looked like:

weekly-journal-pic-1

The three LED behaviors which we recreated were a slow blink which turned faster while the button was held down, a blink which became increasingly faster with each press of the button, and lastly a two button setup which shot the blink down either side of the strip of LEDs.  For an example of the results, the pictures below are the code from the first behavior.

In this example, you can see that the first thing done is to #include the debounce library which was downloaded from the internet.  The next step was to declare the variables, which also included declaring the debounce library and the buttonState.  Next, in the setup section we stated the pinMode for each of the Arduino’s connected pins and the debouncer.  In the loop section we began by initializing the debouncer and communicating to the Arduino to read the btnvalue which would tell it whether or not the button was pushed.  Then once the button state was read, the code moves into a for-loop, then reads the button again and loops through a second for-loop.  Through this exercise I was made more comfortable with using the for-loop structure.  In a for-loop there are three main parts which are the initialization, condition, and update.  Within each of the pictured for-loops we have coded for a blink at a different speed.  The first for-loop is a slow blink for when the button is not pushed and the second for-loop is a fast blink for when the button is pushed.  The two main problems which I encountered in trying to write this code were, learning how to incorporate the bounce library and figuring out the correct placement for the brackets.  I was able to troubleshoot these errors several times and eventually resolve them into the code above.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s