Week 5: Microcontrollers

Slides:



Advertisements
Similar presentations
Lab7: Introduction to Arduino
Advertisements

Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Embedded Sumo 1T4 – 1T5 UTRA.
Introduction.
 Main Components:  Sensors  Micro controller  Motor drivers  Chasis.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Embedded Programming and Robotics
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 1 Topics: Microcontrollers Programming Basics: structure and variables Digital Output Analog to Digital Conversion.
Colorado Space Grant Consortium Gateway To Space ASEN 1400 / ASTR 2500 Class #12 Gateway To Space ASEN 1400 / ASTR 2500 Class #12 T-58.
Lecture 9: Microcontrollers – part 1 BJ Furman 29OCT2012.
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
Week 10 Today 1.Homework presentations and critique. 2.Review digital and analog inputs. 3.DIY - jumpers, soldering etc.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Lecture 7: Microcontrollers & I/O Bryan Burlingame 14 October 2015.
Introduction to Arduino Microcontrollers. What is a Microcontroller ? What is a Microprocessor ? A Microcontroller (8 bit) does one task very fast and.
Microcontrollers, Microcomputers, and Microprocessors
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Microcontroller basics Embedded systems for mortals.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Prototyping with Microcontrollers and Sensors. Overview Objective Background Information Problem Statement Materials Procedure Assignment Closing.
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
Arduino Part 1 Topics: Microcontrollers
INTRODUCTION TO ROBOTICS Part 5: Programming
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Week 4: Microcontrollers & Flow Control
By Rick Darby Sponsors: Geekspace Gwinnett The WorkSpot
Assist. Prof. Rassim Suliyev - SDU 2017
Prototyping with Microcontrollers and Sensors
Week 6: Style and Peripherals
Microcontroller basics
Microprocessors Tutorial 1: Arduino Basics
Microcontroller basics
UTA010 : Engineering Design – II
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
Arduino.
Introduction to Arduino Microcontrollers
How to avoid catching things on fire.
The Arduino Microcontroller: Atmel AVR Atmega 328
Introduction to Arduinos
Roller Coaster Design Project
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
Week 6: Microcontrollers II
Arduino 101 Credit(s):
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Arduino programs Arduino toolchain Cross-compilation Arduino sketches
CTY SAR FCPS Shawn Lupoli, Elliot Tan
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Aeroponic Engineering and Vertical Farming
Introduction to Arduino
Lab #1: Getting Started.
Arduino Uno circuit basics
Arduino Board.
Arduino म्हणजे काय?.
Lecture 8: Arduino 20 March 2019.
Setting up a basic program with Arduino
Introduction to Arduinos
Introduction to arduino
Introduction to Arduino IDE and Software
Presentation transcript:

Week 5: Microcontrollers Eric Wertz 21 Feb 2018

Announcements & The Plan for Today™ Homework #3 due next week Discuss the Arduino and embedded systems Read chapter 5 in the text Had planned to talk about blocking and non-blocking code and debouncing switches.

What is a Microcontroller? A small computer usually implemented on a single IC that contains a central processing unit (CPU), some memory, and peripheral devices such as counter/timers, analog-to-digital converters, serial communication hardware, etc. ATmega328 the ‘brain’ of the Arduino http://www.amazon.com/AVR-Pin-20MHz-32K-ATMega328/dp/B004G5AVS6

Where are Microcontrollers Used? Everywhere! Car Phone Toothbrush Microwave oven Copier Television PC keyboard Appliances http://ecomodder.com/wiki/index.php/MPGuino

The Arduino Platform http://arduino.cc/ USB jack Microcontroller power jack Voltage regulator Pwr/GND Pins ICSP Header Reset Button Power LED Pin 13 LED Rx + Tx LEDs Digital Pins Atmel ATmega328 microcontroller 14 digital I/O pins 6 with PWM 6 analog I/O pins 32 kB (-2 kB) Flash memory 2 kB RAM 1 kB EEPROM 16 MHz clock $22 - $30 built $13 ‘breadboardable’ FTDI USB chip Analog Pins http://arduino.cc/

Fundamental Flow of an Arduino Program Start Setup Loop End

A complete Arduino Sketch // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count = blue_count + 1; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop A complete Arduino Sketch with integrated pseudocode Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

A complete Arduino Sketch // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keepsps digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count = blue_count + 1; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop A complete Arduino Sketch with integrated pseudocode Verify the code syntax Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

A complete Arduino Sketch // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keepsps digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count = blue_count + 1; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop A complete Arduino Sketch with integrated pseudocode Upload the code to the board Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

A comment about “Magic Numbers” // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; A comment about “Magic Numbers” It is considered poor form to litter numbers throughout your code Typos with numbers can generate bugs which are wickedly difficult to see Which is correct: 3.1415926535898 or 3.1415926353898 ? Better: Use constant variables to hold any number more complex than one or zero The compiler will catch any typo and you only need to get it correct in one place

An Arduino Sketch begins with the setup This function runs only once The purpose is to initialize the system for use /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } Commonly setup identifies: Which pins are inputs Which pins are outputs Initializes the libraries used for various peripherals Serial console Tones Servo motors Etc. More info: http://arduino.cc

BLUE_LED  byte constant assigned the value of 6 pinMode(PIN, MODE); sets whether a pin is an input, input_pullup or an output BLUE_LED  byte constant assigned the value of 6 OUTPUT, INPUT, and INPUT_PULLUP are constants defined in Arduino Output are signals generated by the Arduino For example, the voltage necessary to turn on an LED Input are signals read by the Arduino INPUT_PULLUP turns is frequently used by switches Turns on a pullup resistor inside the microcontroller connected to high When the switch (button) is pressed, it drives the pin low This is an active low signal /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } Notice how the switch is wired

Serial.begin(COMM_SPEED); starts the serial console The serial console is a way to obtain text information from the Arduino /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } Launch serial console

Serial.begin(COMM_SPEED); starts the serial console The serial console is a way to obtain text information from the Arduino /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } Serial console

Primary system loop void loop() The code in the block repeats forever The loop function launches immediately after the setup function terminates // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

Since the loop routine restarts when it ends usual variables reset on each loop To keep the value of the variable across loops, use the static keyword In this example, blue_count keeps the count through loops // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

In this line, however, blue_count will return to 0 on each loop // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop int blue_count = 0; // Create an int to count blues, resets to zero on every loop digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop In this line, however, blue_count will return to 0 on each loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

digitalWrite(pin, voltage_level); Digital Output digitalWrite(pin, voltage_level); Sets the voltage on a digital pin to either ground (LOW) or 5 Volts (HIGH). Think of a light, either on or off // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

Returns the value detected on a pin (HIGH or LOW) Digital Input digitalWrite(pin); Returns the value detected on a pin (HIGH or LOW) Recall: LOW is returned, when a button is pressed on the experimenter board // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

// Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count = blue_count + 1; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop When the switch is pressed, specifically when a LOW (0V or ground) is detected on the pin connected to switch 0, perform the tasks between the curly braces { } Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

Allows the Arduino to send text output to the PC Serial Output Allows the Arduino to send text output to the PC Serial.print(“String”); prints the string Serial.println(“String”); prints the string and then starts a new line // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_duration); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Serial.print(variable); prints the value of the variable Serial.println(variable); prints the value of the variable and then starts a new line More limited than printf Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

Delay delay(DELAY_IN_MILLISECONDS); // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count++; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Delay delay(DELAY_IN_MILLISECONDS); Delays the system for a number of milliseconds. Blocking operation While the delay is occurring, nothing changes Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever

Delete all nonstatic variables Launch void loop() again // Symbolic Constants///////////////////////////////////////////////////// const int BLUE_LED = 6; const int SWITCH0 = 12; const int COMM_SPEED = 9600; const int SLEEP_DURATION = 250; /////////////////////////////////////////////////////////////////////////// void setup() // Initialize the system for use { pinMode(BLUE_LED, OUTPUT); // Set the blue LED pin to output pinMode(SWITCH0, INPUT_PULLUP); // Set switch 0 to input with pullup Serial.begin(COMM_SPEED); // Start the serial console } ///////////////////////////////// //////////////////////////////////////// void loop() // Primary system loop static int blue_count = 0; // Create an int to count blues, keeps the count through loops digitalWrite(BLUE_LED, LOW); // turn off the blue LED if(LOW == digitalRead(SWITCH0)) // if the button is pressed digitalWrite(BLUE_LED, HIGH); // turn on the blue LED blue_count = blue_count + 1; // add one to the running blue count Serial.print("Blue Count: "); // print "Blue Count:" Serial.println(blue_count); // print the actual count and a newline delay(SLEEP_DURATION); // sleep for SLEEP_DURATION } // Go back to the start of loop Introduce the concept of a complete Arduino sketch, with two main parts: a setup function which runs once and a loop function which repeats forever Repeat the loop Delete all nonstatic variables Launch void loop() again

Spartronics Experimenter Digital Pin Assignments 13 12 11 10 9 8 7 6 5 4 3 2 1 SCK MISO MOSI SS OC1 ICP AIN1 AIN0 T1 T0 INT1 INT0 TXD RXD LED pwm LED0 LED1 LED2 LED3 green blue red piezo servo SW0 SW1 SW2 SW3 Piezo rectangle is hyperlinked to an image of the actual Experimenter board. The piezo speaker is hyperlinked back to this slide.

Spartronics Experimenter Analog Pin Assignments 7 6 5 4 3 2 1 photocell POT temp sensor The rectangle around cells for pins 2, 1, 0 are hyperlinked to an image of the actual Experimenter board. Each respective element is hyperlinked back to this slide.

References Modular Programming in C http://www.icosaedro.it/c-modules.html math.h http://www.opengroup.org/onlinepubs/007908799/xsh/math.h.html