living with the lab - Louisiana Tech University

Download Report

Transcript living with the lab - Louisiana Tech University

living with the lab
Using the Arduino to Make an LED Flash
Work in teams of two!
14 digital I/O pins
(I/O = input / output)
USB cable plug
power pins
6 analog input pins
1
© 2012 David Hall
1
living with the lab
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.
2
living with the lab
The Circuit
digital I/O
pin 0
470W
digital pin 0
NOTE: It would probably be better to use a different pin than digital pin 0 since this pin
receives information from your computer through the USB cable. The RX printed beside
pin 0 and the TX printed beside pin 1 mean “receive” and “transmit,” respectively.
3
living with the lab
enter and run the following sketch
Enter and run the following sketch:
void setup() {
// initialize the digital pin as an output:
pinMode(0, OUTPUT);
}
void loop() {
digitalWrite(0, HIGH); // set the LED on
delay(1000);
// wait for a second
digitalWrite(0, LOW); // set the LED off
delay(500);
// wait for 500 ms
}
4
living with the lab
how the sketch works
void setup() {
initialize pin 0 as an output
void loop() {
digitalWrite(0, HIGH);
delay(1000);
digitalWrite(0, LOW);
delay(500);
}
set pin 0 to HIGH (5V)
wait 1000 ms
set pin 0 to LOW (0V)
wait 500 ms
1000 ms
voltage (V)
infinite loop
pinMode(0, OUTPUT);
}
500 ms
5V
0V
time (ms)
HIGH = 5V and
LOW = 0V
(Always!!!!)
5
living with the lab
Now Experiment on Your Own!
(1) Try changing the time to 1.5 seconds on and 1 second off
(2) Connect the resistor to digital pin 5 and change the program to match
(3) Blink out SOS in Morse code (dot-dot-dot-dash-dash-dash-dot-dot-dot)
a. three short pulses (0.25 seconds each) followed by . . .
b. three long pulses (0.75 second each) followed by . . .
c. three short pulses (0.25 seconds each) followed by . . .
d. a brief pause (1 second)
e. repeat a through d using an infinite loop
Show your instructor when you have completed exercise (3)
6
living with the lab
Find each command in the reference section of arduino.cc
(discuss each command with others at your table)
void setup() {
// initialize the digital pin as an output:
pinMode(0, OUTPUT);
}
void loop() {
digitalWrite(0, HIGH); // set the LED on
delay(1000);
// wait for a second
digitalWrite(0, LOW); // set the LED off
delay(500);
// wait for 500 ms
}
The End 
7