// Define pins for LEDs
const int ledPins[] = {8, 9, 10, 11}; // LED pins
const int buttons[] = {1, 2, 3, 4};
void setup() {
// Initialize the LEDs and start Serial communication
Serial.begin(115200);
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(buttons[i], INPUT_PULLUP);
}
}
void loop() {
// Check if data has been sent through Serial
for (i = 0; i < 4; i++){
if (Serial.available() > 0) {
int button = Serial.parseInt(); // Read user input
}
if (button == 1){
digitalWrite(8, HIGH);
}
else if (button == 01){
digitalWrite(8, LOW);
};
if (1 == LOW && lastButtonState == HIGH) {
ledState = !ledState; // Toggle the LED state
digitalWrite(ledPin, ledState ? HIGH : LOW);
}
}
}
// A program to use 4 different buttons to turn on and off 4 different LEDs
const int buttonPins[] = {2, 3, 4, 5};
const int ledPins[] = {8, 9, 10, 11};
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < 4; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}
//This is for the second assignment.