NODIEPONS Lab1
NODIEPONS Lab1
PONPON IOT01
BTVTEd – CP3
LAB 1
1. Describe what will happen in LED if you change the delay to 500? What will also
happen if you change the delay to 2000? Why do you think it happens?
The light flicker delay will be.5 seconds, or half a second, if I alter the delay to 500. If I set it
to 2000, it will translate to 2 seconds, and the light will flicker after every 2 seconds. The
delay could also refer to the length of time the light is on. It occurs because the delay ()
function instructs the Arduino to suspend execution for the duration of the time you provide.
2. What will happen if you change the ‘led’ variable into ‘abc’ variable in the declaration
part? What will you do to use the ‘abc’ as your variable?
If I change the declaration's 'lead' variable to 'abc,' I will need to make adjustments across my
routines that use the 'abc' variable. I can substitute "int abcPin = 2" for "int ledPin = 2". I now
need to change the led section of the code to abc, for example, "digitalWrite (ledPin, HIGH);"
to "digitalWrite (abcPin, HIGH);" when writing the entire program. Just be careful not to
overlook anything when changing the codes to abc.
1. Write a program that will blink 2 LEDs alternately. You may use any delay.
int led1 = 2;
int led2 = 3;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(500);
}
2. Write a program that will use 5 LEDs that will blink from left to right consecutively.
void loop() {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(500);
digitalWrite(ledPins[i], LOW);
}
}
3. Write a program that will use 5 LEDs that will blink 2 times simultaneously, 2 times
consecutively from left to right, and 2 times consecutively from right to left
repeatedly.
int ledPins[] = {2, 3, 4, 5, 6};
int numLEDs = sizeof(ledPins) / sizeof(ledPins[0]);
void setup() {
for (int i = 0; i < numLEDs; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
for (int count = 0; count < 2; count++) {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
}
In this project, we connected lights to Arduino so that we could program them to light
up in various ways. Just 2 lights are blinking, and adding 5 lights to the breadboard causes
even more blinking. Lights flicker at certain periods because of various delays.
You may change the order in which the lights appear by using various codes with the
Arduino application. They can be lit in either a right-to-left or a left-to-right order, or all at
once.
Overall, as a programming major, this hobby gives me delight and information.