DigiELECS 2 Lab Act 2
DigiELECS 2 Lab Act 2
Name: Date:
Rating:
Introduction
Example #1: This simple program makes a LED connected to pin 13 blink.
Example#2: Running Light using boolean
Schematic Diagram
void loop()
{
digitalWrite(cea,HIGH);
delay(50);
digitalWrite(cea,LOW);
if(ece == true)
{
cea = cea - 1;
}
else
{
cea = cea + 1;
}
if(cea < 4)
{
cea = 5;
ece = false;
boolean ece = true;
}
int cea = 12;
if(cea > 12)
void setup()
{
{
cea= 11;
pinMode(12,OUTPUT);
ece = true;
pinMode(11,OUTPUT);
}
pinMode(10,OUTPUT);
pinMode(9,OUTPUT); }
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
}
Example#3: Running Lights using digitalWrite
pinMode(ledRed, OUTPUT); }
} void setup() {
// use a for loop to initialize each pin as an
void loop()
output:
{ for (int ece = 2; ece < 8; ece++) {
pinMode(ece, OUTPUT);
digitalWrite(ledRed, HIGH);
}
digitalWrite(ledGreen, LOW); }
int pinButton = 8;
int LED = 2;
void setup() {
pinMode(pinButton, INPUT);
pinMode(LED, OUTPUT);
void loop() {
if(stateButton == 1) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
Problem #1:
Condition:
Sequence 1:
• Once the power has been plug, it will have a delay of 2s to turn on the first LED. After 2s, the
first LED will turn on and won’t turn off. After 4s after the power has been plug, the second
LED will turn on and also won’t turn off. The third LED will turn on after 6s until the last LED
has been reached, and additional of 2s delay to turn on is being add in each LED.
• After the last LED turn on, they will turn off individually starting from the last LED with a delay
of 500 ms each interval.
Sequence 2:
• LED # 2,4,6,8 will turn on for 2s and turn off. Without delay, the remaining LED will turn on
for the same delay. This sequence will repeat 3 times.
Sequence 3:
Problem #2:
Condition:
• When the first button is pressed, the first condition of the led will run. When the 2 nd
button is pressed, the first sequence will stop, and the 2 nd sequence of led will run and
when the last button is pressed, the last sequence will run.
Note:
Observation:
Conclusion:
References: