CSC306 Codes
CSC306 Codes
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);
}