IOT Virtual Lab
Home
Simulation Window
Go Back
Interfacing of Arduino with Slider Switch :
ARDUINO CODE
int ledRed = 13; int ledGreen = 12; int switchPin = 7; void setup() { pinMode(ledRed, OUTPUT); pinMode(ledGreen, OUTPUT); pinMode(switchPin, INPUT); } void loop() { int SwitchV = digitalRead(switchPin); // Read the status of Slider Switch. if( SwitchV == HIGH) // Check whether the switch is HIGH or not. { digitalWrite(ledRed,1); //Turn on Red LED. digitalWrite(ledGreen,0); // Turn off Green LED. } else { digitalWrite(ledRed,0); // Turn on Green LED. digitalWrite(ledGreen,1); // Turn off Red LED. } }
Start Simulation