I am a newbie and I am sorry if this may be a duplicate post, but I could not find one for what I need. Also, sorry if I get long winded. I like to be detailed in my explinations.
My primary goal is shrinkify this circuit and integrate this circuit into my car's brake light system using home made LED fixtures.
I am trying to get 1 high power analog output to be controlled by 2 different digital inputs (1 switch, 1 button) but have different states depending the state of the digital inputs. Eventually the switch and button will be replaced by my car's 12VDC outputs for driving lights and brake light wires.
For future modifications, I would like the LED to strobe 2 or 3 times (delay(50); on and off) before staying on solid until the button is released.
A slide switch is connected to pin 12
A push button is connected to pin 7
The LED's are connected to pin 9 via a MOSFET Transistor (The LED's (196 total) are rather powerful and needs more power than the Arduino can supply)
I want the LED to turn on dim (50) when the slide switch is turned on
and/or
I want the LED to turn on bright (255) when the button is pressed
The LED will go bright (255) regardless of the state of the switch. The switch will simply control weather the LED is dimmed (50) or off (0) when the button is not pressed.
So far, have been able to make the LED start dim (50) and go bright (255) when the button is pressed, but I cannot figure out how to incorporate the slide switch at the same time.
Here's what I have so far that works:
#define LED 9 // The Brake Light LED is connected to pin 9
const int BUTTON = 7; // A test button is connected to pin 7
const int SWITCH = 12; // A test switch is connected to pin 12
int val = 0;
int OFF = 0;
int DIM = 50; // Appropriate brightness when dimmed for this LED fixture
int BRIGHT = 255;
void setup() {
pinMode(13, OUTPUT); // This LED isn't used for this setup, however it is installed
pinMode(LED, OUTPUT); // Pin 9 is an output
pinMode(BUTTON, INPUT); // The button connected to pin 7 is an input
pinMode(SWITCH, INPUT); // The switch connected to pin 12 is an input
}
void loop()
{digitalWrite(13, LOW); // Turn off the LED on pin 13
val = digitalRead(BUTTON); // Read the ON/OFF state of the button
if (val == HIGH) // If the button is being pressed
{analogWrite(LED, BRIGHT); // turn the brake light on full power
delay(2000);} // Wait 2 second before going back to dim (prevents the "strobing" effect)
else // otherwise
{analogWrite(LED, DIM);}} // run the brake light in a dimmed state