uint8_t SW1;
uint8_t SW2;
uint8_t SW3;
uint16_t adc;
uint8_t Data;
void setup() {
// Initialize serial communication at a baud rate of 115200
Serial.begin(115200);
// Set pin modes for switches
pinMode(19, INPUT_PULLUP); // SW 1
pinMode(18, INPUT_PULLUP); // SW 2
pinMode(5, INPUT_PULLUP); // SW 3
// Set pin modes for LEDs
pinMode(4, OUTPUT); // LED 1
pinMode(2, OUTPUT); // LED 2
pinMode(15, OUTPUT); // LED 3
// Set pin mode for variable resistor (potentiometer)
pinMode(36, INPUT); // Variable Resistor
}
void loop() {
// Read switch states
SW1 = digitalRead(19);
SW2 = digitalRead(18);
SW3 = digitalRead(5);
// Read analog value from variable resistor
adc = analogRead(36);
Data = (adc * 100) / 4096;
// Print the data value to the serial monitor
Serial.print("Data: ");
Serial.println(Data);
// Control LEDs based on switch states
digitalWrite(4, SW1 ? LOW : HIGH); // LED 1 controlled by SW1
digitalWrite(2, SW2 ? LOW : HIGH); // LED 2 controlled by SW2
digitalWrite(15, SW3 ? LOW : HIGH); // LED 3 controlled by SW3
// Add a small delay to avoid reading switches too frequently
delay(100);
}