I've searched for the last few days, but to no available can I find an answer to my question.
I can find many places of using analog input to adjust the brightness of an LED strip using a potentiometer, but not a digital high (1).
My question is I'm look to have lights on at a dim brightness level, and with a digital input pin goes high the lights go bright. This seems like a straight forward concept, but I'm way too new to begin to fathom on how to do it.
PIN_A (dim) would just be either on or off based on pin 5
PIN_B (full bright) would go momentarily bright when ever pin 6 is HIGH, but if pin 5 is high, it goes back to the PIN_A state
Any help is greatly appreciated. And excuse me please if I'm in the wrong area to ask or am not clear enough.
#include <FastLED.h>
#define LED_TYPE WS2812B // Define LED Type (eg WS2812B)
#define VOLTS 5 // Define Arduino output voltage to help protect lights
#define MAX_MA 600 // Define max current draw.
#define COLOR_ORDER GRB // Define Red Green Blue of the WS2812B LED strip; refer to Data Sheet
#define NUM_LEDS 10 // Define number of LEDs
#define BRIGHTNESS 230 // Define max brightness
#define PIN_A 5 // Define input pin A
#define PIN_B 6 // Define input pin B
#define LED_PIN 7 // Define output LED Pin
CRGB pin_a_leds[NUM_LEDS];
CRGB pin_b_leds[NUM_LEDS];
void setup() {
delay(3000); // power-up safety delay
FastLED.addLeds<WS2812B, LED_PIN, GRB>(pin_a_leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
pinMode(PIN_A, INPUT);
}
void loop() {
// Read the state of the inputs
bool PinAInput = digitalRead(PIN_A);
bool PinBInput = digitalRead(PIN_B);
// Lights On (Dim when on)
if (PinAInput) {
fill_solid(pin_a_leds, NUM_LEDS, CRGB::White);
// LIGHTS ON AT A LOWER BRIGHTNESS LEVEL CODE HERE
} else {
fill_solid(pin_a_leds, NUM_LEDS, CRGB::Black);
}
// Lights brighter when selected PIN_B input is HIGH)
if (PinBInput) {
fill_solid(pin_a_leds, NUM_LEDS, CRGB::White);
} else {
fill_solid(pin_a_leds, NUM_LEDS, CRGB::Black);
}
FastLED.show();
}
confusing. looks like there are 2 pins controlling pin_a_leds
buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.
You set the brightness during setup and you never change it.
You've got 4 possible states but apparently only 3 conditions (bright, dim, and off). That's OK as long as the "extra" state gives you the right condition. For example, maybe A is for bright/dim and B might be for on & off.. So if B is low, A is ignored.
I think you need to nest your if-statements or you can use AND to test the combination of switch settings... That is, check the state of both switches before you decide what to do.
The way you've got it now, every time through the loop it's possible to write a "Black" immediately followed by "White" or vice-verse. That might make the LEDs appear dim (whenever they conflict) and that might be OK, or it might make them flicker.
This is essentially going to be custom tail lights for my BIL.
But after thinking about it. Ill have a seperate strip for A and B.
So Pin A would be just the tail lights on ( think night time), and Pin B would be the brakes. (Yes theres others, but I want to get these two down before I get into a rabbit hole and will expand from here.
Im making it two separate strips as just as in your car there are two filaments in a bulb. Just added safety IMO.
The "switch" is essentially the brake pedal (12-14.4VDC) in Pin B's case. On one circuit line the source voltage will go through a 10k voltage divider network then regulated by a 5.1V Zener. This regulated voltage becomes the (HIGH). The other line will go through a diode (basic 1N4007) then to a DC step down to make it 5VDC to power the arduino and led strips.
I have a schematic done out, just not at home ATM to post but Im hoping that's ok.
Then you'd figure Id be able to just call one if a button is pressed. The problem is that #define brightness (value) is a global entry for fastLED. Is that ny issue here?