I am trying to program a sketch such that an LED will light up for as long as a push button is pressed down. I have tested the components and electronics configuration before with a simpler program, and it all works, but there seems to be a problem in the code. I wanted to know how my sketch may be altered so the code will work:
const int ledPin = 12;
const int switchPin = 2;
const int Time = 100;
int buttonState = 0;
int count = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
buttonState = digitalRead(switchPin);
while (buttonState == HIGH) {
count++;
delay(100);
}
count=count*10;
if (count>1) {
digitalWrite(ledPin, HIGH);
delay((count*10));
digitalWrite(ledPin, LOW);
}
}