Arduino: For Loops.

Slides:



Advertisements
Similar presentations
temperature system wiring
Advertisements

Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby.
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.
Cascaded switching of a solenoid valve living with the lab transistor relay solenoid valve © 2012 David Hall.
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.
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.
Building Circuits.
Pump Fabrication Day Group A will draw their pump
Controlling Servos with the Arduino
Connecting Switches.
Series and Parallel Resistors
Pump Project Requirements
Introduction to the Arduino
Why Won’t My Arduino Work?
Robot Challenge Introduction
Troubleshooting Your Multimeter
Using servos.
Servo Library and Functions
Line Following Tips photoresistor circuits
Pump Project Overview.
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.
Introduction to Transistors
Servo Library and Functions
Troubleshooting Your Multimeter
a few of my favorite sensors
Relays.
using for loops to control LEDs
using the Arduino to make LEDs flash
Acquiring Data from an ADXL335 Accelerometer
Using Photoresistors with an Arduino
Line Following Tips photoresistor circuit
Torque and RPM of Gears
Conservation of Mass Problem
Data Types.
analog and digital measurements
Using “if” statements.
Controlling the Heater
Design Project Forecast
Digital Input from Switches
Cash Flow Diagrams <in> <out> $200 $300 $150 $100
Implementing Switches Using Interrupts
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
Brainstorming.
Conservation of Mass Problem
Non-Concurrent Force Systems
Evaluating Design Alternatives
Counting Servo Gear Teeth (FS90R Servos)
Static Equilibrium Problem
Reservoir Loop.
Freshman Design Expo Presentations
Presentation transcript:

Arduino: For Loops

DISCLAIMER & USAGE The content of this presentation is for informational purposes only and is intended for students attending Louisiana Tech University only. The authors of this information do 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 damage and injury. Louisiana Tech University, its officers, employees, agents and 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. The Living with the Lab logos should remain attached to each slide, and the work should be attributed to Louisiana Tech University. If you do not agree, then please do not view this content. boosting application-focused learning through student ownership of learning platforms

Build this Circuit then Implement the Code 470W digital I/O pin 11 void setup(){ pinMode(11, OUTPUT); for(int i=0; i<5; i++) { digitalWrite(11,HIGH); delay(200); digitalWrite(11,LOW); delay(200); } void loop() {

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,…,22, 21) for(int i=0; i<80; i+=2) { } • increment i by 2 each time (0,2,4,6,…,76,78) for(int i=50; i>=0; i-=5) { } • decrement i by 5 each time (50,45,40,35,…,5,0) for(int i=2; i<100; i=i*1.5) { } • multiply i by 1.5 each time (2,3,4,6,9,13,19,28,42,63,94)

Experiment 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

Click here to get serial monitor to display Play around…ideas for different patterns to display: Click here to get serial monitor to display 1,2,3,…100 100,99,98,…-27 0,3,6,9,…69 1000,950,900,…50 1,2,4,8,16,…1024 1024,512,256,…1 1,4,9,16,25,…100