using for loops to control LEDs

Slides:



Advertisements
Similar presentations
Why won’t my Arduino work???? living with the lab © 2012 David Hall.
Advertisements

temperature system wiring
College of Engineering & Science living with the lab Ohm’s Law © 2012 David Hall 1.5V.
Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby.
Conductivity sensor implementation living with the lab © 2011 LWTL faculty team.
Analog and Digital Measurements living with the lab 14 digital input / output pins 6 analog input pins © 2012 David Hall.
Waterproofing a thermistor ENGR 121 living with the lab © 2013 David Hall.
Using the Arduino to Make an LED Flash Work in teams of two! living with the lab digital I/O pins (I/O = input / output) USB cable plug power pins.
User-defined functions in Arduino sketches living with the lab © 2012 David Hall.
Calibration of conductivity sensors living with the lab.
Using Your Arduino, Breadboard and Multimeter Work in teams of two! living with the lab 1 © 2012 David Hall.
Thermistor calibration living with the lab © 2013 David Hall.
Cascaded switching of a solenoid valve living with the lab transistor relay solenoid valve © 2012 David Hall.
Assembly of conductivity flow loop living with the lab (in preparation for calibrating conductivity sensor)
Switches & whiskers on the Arduino living with the lab lever arm switches mounted to Arduino © 2012 David Hall.
Using fixed-cell references and built-in functions in Excel living with the lab © 2012 David Hall.
220  470  Gnd5V Currents Through Parallel Resistors 1 living with the lab © 2012 David Hall.
Using Hobby Servos with the Arduino living with the lab © 2012 David Hall.
Introduction to Microsoft Excel living with the lab © 2012 David Hall.
Voltage Drops Around Closed Loops 470  220  5V   220  living with the lab © 2012 David Hall.
Navigating the engineering disciplines robot challenge living with the lab © 2012 David Hall.
Kirchoff’s Current Law (KCL) living with the lab University of Pennsylvania Library and Wikipedia Gustav Kirchoff (left) and Robert Bunsen (right) Bunsen.
Adding a Barrel Jack to a Battery Pack living with the lab © 2012 David Hall.
Using for loops to control LEDs living with the lab 1 1 arduino.cc the for statement allows us to repeat a block of commands a limited number of times.
Pump Fabrication Day Group A will draw their pump
Controlling Servos with the Arduino
Connecting Switches.
Series and Parallel Resistors
Introduction to the Arduino
Why Won’t My Arduino Work?
Troubleshooting Your Multimeter
Using servos.
calibration of conductivity sensors
Servo Library and Functions
Line Following Tips photoresistor circuits
Robot Assembly.
How to Use Dial Calipers
Controlling a Motor with Cascading Switches
Introduction to Transistors
Introduction to the Fishtank
RGB LEDs.
Conservation of Mass Problem
Maxbotix Ultrasonic Distance Sensor
Conductivity Sensor.
Schedule 8:00-11:00 Workshop: Arduino Fundamentals
Introduction to Transistors
Servo Library and Functions
Troubleshooting Your Multimeter
a few of my favorite sensors
using the Arduino to make LEDs flash
Acquiring Data from an ADXL335 Accelerometer
Using Photoresistors with an Arduino
Line Following Tips photoresistor circuit
Conservation of Mass Problem
analog and digital measurements
Using “if” statements.
Controlling the Heater
Digital Input from Switches
Implementing Switches Using Interrupts
Arduino: For Loops.
Non-Concurrent Force Systems
IR Object Detection IR detector IR LED IR light reflected off object
Radio Frequency Transmitter and Receiver
Interfacing a Rotary Encoder with an Arduino
Conservation of Mass Problem
Non-Concurrent Force Systems
Evaluating Design Alternatives
Counting Servo Gear Teeth (FS90R Servos)
Static Equilibrium Problem
Freshman Design Expo Presentations
Presentation transcript:

using for loops to control LEDs the for statement allows us to repeat a block of commands a limited number of times arduino.cc

DISCLAIMER & USAGE The content of this presentation is for informational purposes only and is intended only for students attending Louisiana Tech University. The author of this information does not make any claims as to the validity or accuracy of the information or methods presented. Any procedures demonstrated here are potentially dangerous and could result in injury or damage. Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are not liable or responsible for any injuries, illness, damage or losses which may result from your using the materials or ideas, or from your performing the experiments or procedures depicted in this presentation. If you do not agree, then do not view this content. The copyright label, the Louisiana Tech logo, and the “living with the lab” identifier should not be removed from this presentation. You may modify this work for your own purposes as long as attribution is clearly provided.

same circuit as before 470W digital I/O pin 2

these sketches both make the LED blink 5 times without for statement with for statement void setup(){ pinMode(11, OUTPUT); digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); } void loop() { void setup(){ pinMode(11, OUTPUT); for(int i=0; i<5; i++) { digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); } void loop() {

how the for statement works declare i as an integer (a number that can vary between -32,768 and 32,767) the first value of i will be zero continue to loop as long as i is less than 5 increment i each time through loop i=0 the first time through loop i=1 the second time through loop i=2 the third time through loop i=3 the fourth time through loop i=4 the fifth time through loop for(int i=0; i<5; i++) { digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); }

incrementing for loops for(int i=0; i<5; i++) { } - increment i by one each time (0,1,2,3,4) for(int i=100; i>20; i--) { } - decrement i by one each time (100,99,98,…) for(int i=0; i<80; i+=2) { } - increment i by 2 each time (0,2,4,6,…) for(int i=50; i>=0; i-=5) { } - decrement i by 5 each time (50,45,40,…) for(int i=2; i<100; i=i*1.5) { } - multiply i by 1.5 each time (2,3,4,6,9,13,…)

play around with incrementing and decrementing for loops void setup() { Serial.begin(9600); for(int x=0; x<100; x++) { Serial.println(x); } void loop() { send output to serial monitor