Hey all,
I have an issue that has me baffled for such a simple sketch. The project is a PWM dimmer to control a set of automotive LED lights. When the output is held LOW, the lights are at full brightness, when I send them a PWM frequency, they are dimmed. I am using a pro-mini 5V/16MHz board and the lights are a pair of VisionX solo prime that have a flying lead for a dimmer application.
My code is as follows:
const int dimmer_OUT = 10; //name pins
const int highbeam_IN = 9;
void setup()
{
pinMode (dimmer_OUT, OUTPUT); // set pins as input and output
pinMode (highbeam_IN, INPUT_PULLUP);
}
void loop()
{
if(digitalRead(highbeam_IN == LOW)) // check if the highbeam input has been pulled low
{
analogWrite(dimmer_OUT, 200); //dim the lights if true
}
else
{
digitalWrite(dimmer_OUT, LOW); // lights at full brightness if false
}
}
When I run that, the lights are always dimmed like they are only getting the PWM signal. The output never drops when the digital input is connected to 0V. I have tried moving to several other PWM pins with the same result and added the pin 13 led to the function to verify the digital input is working properly and the led lights/goes out when I toggle the input on pin 9.
I wrote an even simpler test sketch to verify the board is OK and it works perfectly as expected without the digital read and if statement.
Test Code:
const int dimmer_OUT = 10; //output to lamps on pin 10
void setup()
{
pinMode (dimmer_OUT, OUTPUT); // set pin to output
}
void loop()
{
analogWrite (dimmer_OUT, 200); // set dimmer value of light
delay (2000); // wait to see if it worked
digitalWrite (dimmer_OUT, LOW); // set lights to full brightness
delay (2000); // wait to see if it worked
}
Thoughts? See something I'm doing wrong?