Untitled
unknown
plain_text
2 years ago
953 B
10
Indexable
// Define pin numbers
const int switchPin1 = 2; //The pin number for the 1st switch
const int switchPin2 = 3; // The pin number for the 2nd switch
const int ledPin1 = 4; // The pin number for the 1st LED
const int ledPin2 = 5; // The pin number for the 2nd LED
void setup() {
// Initialize the LED pins as output
pinMode(ledPin1, OUTPUT); //Set the 1st LED pin is output
pinMode(ledPin2, OUTPUT); //Set the 2nd LED pin is output
// Initialize the switch pins as input
pinMode(switchPin1, INPUT); //Set the 1st switch pin is input
pinMode(switchPin2, INPUT); //Set the 2nd switch pin is input
}
void loop() {
// Read the state of the switches
int switchState1 = digitalRead(switchPin1);
int switchState2 = digitalRead(switchPin2);
// Implement the logic for the LEDs using bitwise operations
digitalWrite(ledPin1, switchState1 & ~switchState2);
digitalWrite(ledPin2, ~switchState1 | switchState2);
}Editor is loading...
Leave a Comment