This week's project was to build a simple circuit consisting of one LED, one 330 ohm resistor, and the Arduino controller board. The project build went very smoothly and without a hitch. The code (seen below) was compiled and loaded to the Arduino controller and the output was captured in the following video.
// Circuit #1 Code
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Video of Controller running Initial Code
In doing further exploration, I added an LED and resistor to the circuit and the code. The LED was
set (in the software) to blink 1s after the original LED shut off. This was done by adding the code
for the second LED inside the loop structure and keeping the same time interval. Here is the code
for the second circuit:
// Circuit #1 Code with Second LED
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 13;
int led2 = 12;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Video of Controller with Secondary LED
For the third circuit, I kept the same physical setup but changed the order of execution
in the code. Although the two LEDs were still blinking, the timing was set differently.
// Circuit #1 Code with Second LED changed flashing
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 13;
int led2 = 12;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
Video of Controller with Secondary LED and changed timing
I initially thought that the projects would be very simplistic for someone that had previous
programming experience. I actually found value in these exercises, though, because of the
complexity of implementing hardware with software. It was fun seeing more than simple
program output change when code is updated. One extension that I would like to make is
creating a traffic light (once I obtain a green LED.)
No comments:
Post a Comment