This Arduino Programming Basics presentation show the power point slides - see the PDF version for a step by step screenshots of what we showed live during the online workshops.
A workshop as part of series of online workshops, stemmed from an LSTA grant to educate librarians and library school students on makerspaces, especially in academic libraries. Nov 12, 2014
2. PARTS! (SAME AS LAST SESSION)
• Arduino
• Components (LEDs, resistors, etc.)
• Your brain
3. ARDUINO CODE
• Based upon C/C++
• Programs created and uploaded to the Arduino
are called sketches.
• Sketches can be created in notepad or other
text editors.
4. LAST SESSION’S LESSON
• We made an LED blink.
• We turned it on, waited, and then turned it off.
• Doing this fast enough made it appear to
blink.
5. THIS SESSION?
• We will work an array of blinking LEDs.
• By controlling the order, the array appears to
be sweeping.
• We will start with explicitly turning each LED
on and then off.
• …then we will do the same with loops.
6. WHAT ARE LOOPS?
• A loop performs a task repeatedly until a
condition is met.
• Some loops are based upon incrementing or
decrementing a variable.
• Remember, the base code in an Arduino sketch
uses a loop – void loop()
7. FOR LOOP?
• A FOR loop performs a task for as long as the
condition is met.
• Usually in the format:
• Set a variable equal to some number.
• Make sure the variable is less than (or greater than)
another number.
• Perform a mathematical operation (usually addition
or subtraction) on the variable to change its value.
• Start over.
8. A FOR LOOP LOOKS LIKE:
• for(int i = 1; i < 10; i = i + 1){ repeated actions }
• int i = 1
• Set the variable ‘i’ equal to 1.
• You don’t have to use ‘i’ if you don’t want to do so. Choose
one that makes sense to you, but be consistent.
• i < 10
• We are only going to do the actions inside of the curly braces
{}
for as long as i is less than 10.
• We will keep repeating these actions until i equals 9.
• Once i equals 10, the loop stops before anything happens.
• i = i + 1
• Once we have run through the loop with i equal to 1, we will
start over with i equals 2.
9. WHY LOOPS?
• Because we are lazy inherently efficient.
• Type a short command many times -or-a
medium command once.
• Speaking of lazy:
• i = i + 1 can be written i++
• i = i - 1 can be written i--
• (why press five buttons when three will do?)
• Like this:
For (int i = 1; i < 10; i++){}