COMPTECH-315-BIT-III-B-Module-02-LED-DISPLAY-WITH-PUSHBUTTON-Part-2 KENISU

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Republic of the Philippines

CEBU TECHNOLOGICAL UNIVERSITY


NAGA EXTENSION CAMPUS
Central Poblacion, City of Naga, Cebu, Philippines
Website: http://www.ctu.edu.ph E-mail: ctunagaextensioncampus@gmail.com
Phone: +6332 417 0418

COLLEGE OF TECHNOLOGY

MIS Code : __________ Schedule : 01:00 PM-04:00 PM MON-FRI

Course Subject : COMPTECH 315 (Microprocessor System) Room No. : Room 311

Curriculum : BIT-COMPTECH Instructor : AL D. HORTEZA, LPT, Ph.D.

Semester : 1st Semester Academic Year : AY 2023-2024

MODULE 02
LED DISPLAY WITH PUSHBUTTON – PART 2

LEARNING OBJECTIVES:
 To construct a microprocessor/microcontroller circuit using Arduino Uno with pushbuttons as input
components and resistors and light-emitting diodes (LEDs) as output components.
 To program a microprocessor/microcontroller circuit based on the required output. In this module, the
required output is to light the LEDs based on the following conditions:
 Left-To-Right when switch 1 is on, switch 2 is off, and switch 3 is off.
 Right-To-Left when switch 1 is off, switch 2 is on, and switch 3 is off.
 Both Sides-To-Center and Center-To-Both Sides when switch 1 is off, switch 2 is off, and switch 3 is on.

LIST OF COMPONENTS:

Item No. Item Description Quantity


1 Breadboard 1 pc
2 Arduino UNO R3 1 pc
3 330 ohms 1/4W Resistor 8 pcs
4 Light-Emitting Diodes (LEDs) 8 pcs
5 Pushbutton 3 pcs
6 10 kilo-ohms 1/4W Resistor 3 pcs
7 AWG #22 Solid Wire

CIRCUIT DIAGRAM:
Republic of the Philippines
CEBU TECHNOLOGICAL UNIVERSITY
NAGA EXTENSION CAMPUS
Central Poblacion, City of Naga, Cebu, Philippines
Website: http://www.ctu.edu.ph E-mail: ctunagaextensioncampus@gmail.com
Phone: +6332 417 0418

COLLEGE OF TECHNOLOGY
SOURCE CODE:

#define inputSwitch1 10
#define inputSwitch2 11
#define inputSwitch3 12

int i,temp;
int displayLED1[8]={2, 3, 4, 5, 6, 7, 8, 9};
int displayLED2[8]={2, 3, 4, 5, 6, 7, 8, 9};
int displayLED3[8]={2, 3, 4, 5, 6, 7, 8, 9};

int inputSwitch[3]={inputSwitch1, inputSwitch2, inputSwitch3};


int switchStatus1 = 1;
int switchStatus2 = 1;
int switchStatus3 = 1;

void setup() {
for(i=0;i<8;i++) //i++ --> i = i + 1 --> i += 1
pinMode(displayLED1[i], OUTPUT);

for(i=0;i<3;i++) //i++ --> i = i + 1 --> i += 1


pinMode(inputSwitch[i], INPUT);

for(i=0;i<8;i++)
digitalWrite(displayLED1[i], LOW);
delay(300);

Serial.begin(9600);
}

void loop() {

switchStatus1 = digitalRead(inputSwitch1);
switchStatus2 = digitalRead(inputSwitch2);
switchStatus3 = digitalRead(inputSwitch3);

Serial.print("Status of Switch 1: ");


Serial.print(switchStatus1);
Serial.print("\n");
Serial.print("Status of Switch 2: ");
Serial.print(switchStatus2);
Serial.print("\n");
Serial.print("Status of Switch 3: ");
Serial.print(switchStatus3);
Serial.print("\n");
delay(10);
Republic of the Philippines
CEBU TECHNOLOGICAL UNIVERSITY
NAGA EXTENSION CAMPUS
Central Poblacion, City of Naga, Cebu, Philippines
Website: http://www.ctu.edu.ph E-mail: ctunagaextensioncampus@gmail.com
Phone: +6332 417 0418

COLLEGE OF TECHNOLOGY

if(switchStatus1 == 0 && switchStatus2 == 1 && switchStatus3 == 1) {


for(i=0;i<8;i++) {
digitalWrite(displayLED1[i], HIGH);
delay(300);
digitalWrite(displayLED1[i], LOW);
}
}
else if(switchStatus1 == 1 && switchStatus2 == 0 && switchStatus3 == 1) {
for(i=7;i>=0;i--) {
digitalWrite(displayLED1[i], HIGH);
delay(300);
digitalWrite(displayLED1[i], LOW);
}
}
else if(switchStatus1 == 1 && switchStatus2 == 1 && switchStatus3 == 0) {
temp = 7;
for(i=0;i<4;i++) {
digitalWrite(displayLED2[i], HIGH);
digitalWrite(displayLED3[temp], HIGH);
delay(300);
digitalWrite(displayLED2[i], LOW);
digitalWrite(displayLED3[temp], LOW);
temp--;
}

for(i=0;i<8;i++)
digitalWrite(displayLED1[i], LOW);
delay(300);

temp = 4;
for(i=3;i>=0;i--) {
digitalWrite(displayLED2[i], HIGH);
digitalWrite(displayLED3[temp], HIGH);
delay(300);
digitalWrite(displayLED2[i], LOW);
digitalWrite(displayLED3[temp], LOW);
temp++;
}

for(i=0;i<8;i++)
digitalWrite(displayLED1[i], LOW);
delay(300);
}
}
Republic of the Philippines
CEBU TECHNOLOGICAL UNIVERSITY
NAGA EXTENSION CAMPUS
Central Poblacion, City of Naga, Cebu, Philippines
Website: http://www.ctu.edu.ph E-mail: ctunagaextensioncampus@gmail.com
Phone: +6332 417 0418

COLLEGE OF TECHNOLOGY

Prepared and Submitted By:

KENT ADRIAN P. PARDILLO


BIT III-B Student, College of Technology
CTU-Naga Extension Campus
Central Poblacion, City of Naga, Cebu 6037 Philippines
As of First Semester, AY 2023-2024

Submitted To:

AL D. HORTEZA, LPT, Ph.D.


Associate Professor V, College of Technology
CTU-Naga Extension Campus
Central Poblacion, City of Naga, Cebu 6037 Philippines
As of First Semester, AY 2023-2024

Date Submitted : ____________________

Date Checked : ____________________

You might also like