0% found this document useful (0 votes)
4 views4 pages

CSC306 Codes

The document contains a code snippet for an Arduino program that initializes an LCD and reads input from four push buttons. It updates the displayed CPU state on the LCD based on which button is pressed. The program includes functions for setting up the LCD and displaying the current CPU state.

Uploaded by

lightomonuku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

CSC306 Codes

The document contains a code snippet for an Arduino program that initializes an LCD and reads input from four push buttons. It updates the displayed CPU state on the LCD based on which button is pressed. The program includes functions for setting up the LCD and displaying the current CPU state.

Uploaded by

lightomonuku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

<LiquidCrystal.

h>
// Initialize the LCD library with
the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11,
12);
const int buttonPins[] = {2, 3, 4,
5}; // Pins for push buttons
int cpuState = 0; // Variable to
hold CPU state
void setup() {
lcd.begin(16, 2);
lcd.print("CPU State: ");
for (int i = 0; i < 4; i++) {
pinMode(buttonPins[i],
INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < 4; i++) {
if (digitalRead(buttonPins[i])
== LOW) {
cpuState = i;

cpuState = i;
displayCpuState(cpuState);
delay(500);
while
(digitalRead(buttonPins[i]) ==
LOW);
}
}
}
void displayCpuState(int state) {
lcd.setCursor(0, 1);
lcd.print("State: ");
lcd.print(state);
}

void displayCpuState(int state) {


lcd.setCursor(0, 1);
lcd.print("State: ");
lcd.print(state);
}

You might also like