I've only just started learning things to do with Arduino, and I've started on my first project. I'm trying to control a 12v LED downlight using a TIP122 transistor and the Arduino Uno SMD to switch it.
The only problem I've run into is the time I have to hold down the button to switch it on/off. If I just quickly push the button and release it, it doesn't actually switch. I have to hold the button down for a second or so for it to switch. Is there a a way around it, or is it a limitation from the Arduino?
The script that I'm using is very basic, but I'll post it anyway. I've also tried it a few ways, but they all act the same.
int ledPin = 13;
int buttonPin = 3;
int ledLight = 0;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
ledLight = digitalRead(ledPin);
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
if (ledLight == HIGH) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
}
}
}