Hello. I want to make a dynamic blinker for my car with WS2812 LED strip. I wrote program, but now I have problem, becuse I can't made programm for command (switch) to turn the blinker on. Can you help me ? Thanks
How can we help with something we can't see?
Sorry, it was my first post. I will add a dokument Today. Thanks for reply
hello
here is my program. Now I want to use a button. I want to turn on the blinker, when I press on the button. Can anyone help me ?
Blink22leds.ino (6.22 KB)
First, you need to get rid of all the delays.
Please read the instructions on posting code.
Delays in which part of code ? The delays betwen leds when I turn its on are correct. All Work fine, I Just only want to run this program by command from button.
If you mean another delays, please tell me.
Thanks for help, I will next time paste the code by instructions.
Delays in all parts of the code.
They need to go, or you need to find another way to make sure that your switch is capable of reacting quickly enough, or accept that once started, your animation must complete before the switch can be read again.
Ok, I understand. I Need to use this code with delays, becuse the another blinkers on car stay original and need to start/blink in the same time.
Do you have any advice, how to write code, which will read the button again when the operation will be complete ?
No, the delays are not necessary.
delays are almost never necessary.
Ok. But then I don’t know, how to write code for dynamic turn signal, if I don’t use a delays.
Take a look at the blink without delay example in the IDE.
What are you using for a signal switch input? To what pin of the Arduino is it connected? What is the active level?
Do you differentiate between left and right turns?
For signal input for test I want to use classic button with 4 pins. On the car I want to use a signal from comfort module, which in the normal lights turn on the blinker.
I want to use button on pin 2 or 3
No, the both sides Need the same code, becuse i will use 2 ArduinoNano, 1 for left and 1 for right
What do you mean with active level ?
zimagame:
No, the both sides Need the same code, because i will use 2 Arduino Nano, 1 for left and 1 for right
Why?
Clearly one Arduino can easily handle at least 17 separate inputs and a chain of WS2812 LEDs with at least 17 sections.
Usually you have the WS2812 LEDs "chase" for the blinkers and possibly for the stop lights as well.
Becuse i will install the arduino back of the light and leave the instalation original and shortest cable as I can.
I know, but if I use 1 Arduino then I Need to instal cables from one to another site...
Try this:
For this example you need to change the turn signal input from LOW to HIGH to start the turn signal LED pattern. When you change it from HIGH to LOW the LEDs should turn off.
/*
* Sketch : sketch_mar03a.ino
* Target : Nano
*
*/
#include <FastLED.h>
#define NUM_LEDS 22
//
#define TURNSW_ACTIVELVL HIGH // level on switch input that indicates turn signal is 'on'
#define TURNSW_CHECKTIME 50ul //mS 50mS interval between signal switch checks
//
#define TURNSW_INTERLED 10000ul //uS 10mS time between LEDs in sequential pattern
#define TURNSW_INTERFLASH 500000ul //uS 500mS off time between completion of sequence and start of next
// Define the array of leds
CRGB leds[NUM_LEDS];
//GPIO
const uint8_t
pinData = 3,
pinTurnSigSwitch = 2;
uint8_t
lastSwitch;
//give the switch return values names
enum switchVals
{
TURNSW_NO_CHANGE=0, //check of signal switch indicates no change from last check
TURNSW_OFF_TO_ON, //turn signal switch changed from "off" to "on"
TURNSW_ON_TO_OFF //turn signal switch changed from "on" to "off"
};
//give each state a name for ease of reading
enum statesSeq
{
ST_IDLE=0,
ST_SEQUENTIAL,
ST_OFFPAUSE
};
void setup( void )
{
// Uncomment/edit one of the following lines for your leds arrangement.
// ## Clockless types ##
FastLED.addLeds<NEOPIXEL, pinData>(leds, NUM_LEDS); // GRB ordering is assumed
pinMode( pinTurnSigSwitch, INPUT_PULLUP );
lastSwitch = digitalRead( pinTurnSigSwitch );
}//setup
void loop( void )
{
//all we do here is check the signal timing. You can add other things to the loop
//if you want; just don't use delays() etc or LED timing will be held-up
SignalTiming();
}//loop
void SignalTiming( void )
{
static uint8_t
stateSignal = ST_IDLE,
ledIndex = 0;
static uint32_t
timeLEDStep;
uint32_t
timeNow = micros();
//check to see if signal switch input has changed
uint8_t switchCondition = CheckSwitch();
//did it change from 'on' to 'off'?
if( switchCondition == TURNSW_ON_TO_OFF )
{
//yes, turn off all LEDs and update the string
for( uint8_t i=0; i<NUM_LEDS; i++ )
leds[i] = CRGB::Black;
FastLED.show();
//set the state to 'idle' where we look for the switch to go from 'off' 'to 'on' again
stateSignal = ST_IDLE;
return;
}//if
switch( stateSignal )
{
case ST_IDLE:
//in idle we wait for switch to go from 'off' to 'on'; has it changed?
if( switchCondition == TURNSW_OFF_TO_ON )
{
//yes; set LED index to zero
ledIndex = 0;
//save the time now
timeLEDStep = timeNow;
//and move to the "sequential" state where the LEDs are lit up in sequence
stateSignal = ST_SEQUENTIAL;
}//if
break;
case ST_SEQUENTIAL:
//here we are turning on the LEDs in sequence
//is it time for a new LED to light?
if( (timeNow - timeLEDStep) >= TURNSW_INTERLED )
{
//yes; save the time now so we can know when to do the next one
timeLEDStep = timeNow;
//have we just finished the last LED?
if( ledIndex == NUM_LEDS )
{
//yes; turn them all black
for( uint8_t i=0; i<NUM_LEDS; i++ )
leds[i] = CRGB::Black;
//and move to the state where we time the 1/2-sec between-flash period
stateSignal = ST_OFFPAUSE;
}//if
else
{
//not at the end yet; light up the LED and bump the index ready for the next
leds[ledIndex++] = CRGB::Orange;
}//else
//update the string
FastLED.show();
}//if
break;
case ST_OFFPAUSE:
//all LEDs have been lit and then turned off; here we wait 1/2-sec (TURNSW_INTERFLASH)
//before starting the sequence again
//has TURNSW_INTERFLASH elapsed?
if( (timeNow - timeLEDStep) >= TURNSW_INTERFLASH )
{
//yes; save the time ready to turn on the 1st LED in sequence
timeLEDStep = timeNow;
//make sure we point to the 1st LED
ledIndex = 0;
//and move back to the sequential state to light the LEDs again
stateSignal = ST_SEQUENTIAL;
}//if
break;
}//switch
}//SignalTiming
uint8_t CheckSwitch( void )
{
static uint32_t
timeSwitch;
uint32_t
timeNow = millis();
//is it time for a switch check?
if( (timeNow - timeSwitch) < TURNSW_CHECKTIME )
return TURNSW_NO_CHANGE; //if not, just return NO_CHANGE
//save this time so we know when to check next
timeSwitch = timeNow;
//read the switch input
uint8_t nowSwitch = digitalRead( pinTurnSigSwitch );
//if it's not the same as last time...
if( nowSwitch != lastSwitch )
{
//save this new state
lastSwitch = nowSwitch;
//if the switch is now "active" or 'on'...
if( nowSwitch == TURNSW_ACTIVELVL )
return TURNSW_OFF_TO_ON; //return that we changed from off to on
else
return TURNSW_ON_TO_OFF; //switch must be off; return that we changed from on to off
}//if
//if here switch read the same as last time so return no change
return TURNSW_NO_CHANGE;
}//CheckSwitch
Thanks
Hello.
now I upload the code and try it. It work great,perfect.
I have only one problem, I need the orange color, but now I have the yellow and I can not change it. can you tell me, how to change it ?
Your turn signal color is set at:
leds[ledIndex++] = CRGB::Orange;
A quick google check informed me that the SAE (Society of Automotive Engineers) defines "amber" for automotive purposes as RGB (255,126,0) (rgb).
It looks like (I could be wrong) that FastLED defines Orange as
..., Orange =0xFFA500, ...
which would be (255,165,0), so it's a little "off" the SAE standard.
You can try experimenting with your color-setting line by changing it to:
leds[ledIndex++] = CRGB( 255, 126, 0);
You might need to tweak and play with the numbers a bit to get a color you like. Try to keep it near the SAE value for legality.
If that color is completely wrong it may be a color-ordering issue (note your "GRB ordering" comment...); if so, swap the first two numbers and see if that gets closer to what you want.