Thanks for a lot of help. I will try today and reply back what was happen.
Now I want to use one more switch/button and turn on with it back reverse light with 12 leds in white volit on the same Led strip with same arduino. can YOU write this code too ?
zimagame:
Thanks for a lot of help. I will try today and reply back what was happen.
Now I want to use one more switch/button and turn on with it back reverse light with 12 leds in white volit on the same Led strip with same arduino. can YOU write this code too ?
I could. But how about you give it a shot -- based on what I gave you -- as a start and see what you come up with?
Sure, I will try at first what can I write alone and than post the code here.
Thanks
zimagame:
Sure, I will try at first what can I write alone and than post the code here.
Make sure you identify how you want the reverse light to work. Planning before coding is important to get the outcome you want.
If the turn signal is on, does the reverse light function override it completely? Or does the turn-signal take precedence? Or do you try to time-slice the two functions together?
Edit: For example: Maybe the inner 1/3 of the strip becomes back up light and the remainder is turn signal.
Hello,
I had a lot of work this weekend and I don’t have time to wrote the code. I will try Today and then post it here.
That is good advice, I will make a plane and then write the code. Yes, that is my idea too, when the blinker is on the 1/3 of light become the reverse and the other will work as a blinker.
Thanks for all help and support.
Have a nice day
/*
* Sketch : sketch_mar03a.ino
* Target : Uno
*
*/
#include <FastLED.h>
#define NUM_LEDS 30
//
#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 REVERSE_ACTIVELVL HIGH
#define REVERSE_CHECKTIME 50ul
//
#define TURNSW_INTERLED 15000ul //uS 15mS time between LEDs in sequential pattern
#define TURNSW_INTERFLASH 500000ul //uS 500mS off time between completion of sequence and start of next
#define REVERSE_INTERLED 0ul
#define REVERSE_INTERLED 0ul
// Define the array of leds
CRGB leds[NUM_LEDS];
//GPIO
const uint8_t
pinData = 3,
pinTurnSigSwitch = 2,
pinReverseSigSwitch = 4;
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"
REVERSESW_NO_CHANGE=0,
REVERSESW_OFF_TO_ON,
REVERSESW_ON_TO_OFF
};
//give each state a name for ease of reading
enum statesSeq
{
ST_IDLE=0,
ST_SEQUENTIAL,
ST_OFFPAUSE,
ST_IDLE1=0,
ST_HIGH,
ST_OFFPAUSE1
};
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 ),
pinMode( pinReverseSigSwitch,INPUT_PULLUP);
lastSwitch = digitalRead( pinTurnSigSwitch ),
lastSwitch = digitalRead( pinReverseSigSwitch );
}//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,
stateSignal = ST_IDLE1
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(255,45,0);
}//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
can you check the code and tell me, if I add the button for reverse light correct ? then I will try to write the code for it.
and I do not know how to tell the controller to check the another button and to turn the reverse light ?
and my plan for this code is:
- num of leds 30
- if reverse light is off then all 30 leds work as turn signal
- if the reverse light is on and turn signal off work first 8 leds in white color
- if the reverse light is on and turn signal on work first 8 leds as reverse and next 22 leds as turn signal switch
- reverse light color (white), turn signal (255,50,0)
You can try the attached (too long for inline)
Compiles, untested.
neopix_turnsigs.ino (10 KB)
Ok, I will try today. Thanks
Those delay()s might come back to bite you when you implement the reverse function.
I’d love to see your code, but I’m on a tablet, and your code hasn’t been posted inline yet.
now I finnaly try the code.
the switch on input 2 do not work. When I press the button connect on pin4, then the reverse light come on the turn signal work squential on other 22 leds.
can you write the code like that:
- when I press button on pin2 work turn switch (all 30leds)
- when I press button on pin4 work reverse light (8leds)
- when I press both buttons work first 8 as reverse and another 22 as turn signal
OK. I took the time to hook it up to my LED string and see that it's not acting as expected. I will get back to you...
I fixed one line in the switch reading function. Copy paste this:
void CheckSwitches( void )
{
static uint8_t
switchIdx=0;
uint32_t
timeNow = millis();
grSwitches[switchIdx].deltaStatus = NO_CHANGE;
if( (timeNow - grSwitches[switchIdx].timeRead) >= grSwitches[switchIdx].timeInterval )
{
grSwitches[switchIdx].timeRead = timeNow;
uint8_t nowSwitch = digitalRead( grSwitches[switchIdx].pin ); //<-- fixed this line
if( grSwitches[switchIdx].lastRead != nowSwitch )
{
grSwitches[switchIdx].lastRead = nowSwitch;
grSwitches[switchIdx].state = (nowSwitch == grSwitches[switchIdx].activeLevel) ? true : false;
grSwitches[switchIdx].deltaStatus = (nowSwitch == grSwitches[switchIdx].activeLevel) ? OFF_TO_ON : ON_TO_OFF;
}//if
}//if
switchIdx++;
if( switchIdx == 2 )
switchIdx = 0;
}//CheckSwitch
YES, that work perfect

now I need to instal it in a car. do you maybe know, how to connect pin2 and pin4 on car 12v and use a signal from car to make the operation ?
Ok, I will try with this wiring. Can I get signal from + wire ? Becuse the ground is constant
hello,
I tried the wiring which you advised me, but it does not work. The Reverse light and the blinker work all the time when I have power supply on my arduino.
when I connect the PIN2 or PIN4 on ground then the leds turn off.
on the car, I have constant/whole time ground and the blinker is controlled by the +. Do you have any idea, how to make this wiring for this light ?
please for help
Please show all of your wiring. Draw a diagram of everything, including the vehicle-side of things.
If you can, measure the voltage at the point labeled "Arduino input" for both cases: switch 'on' and switch 'off.'
Afere my post I try to change the basic state of switch from high to low. Now can I plug the power supply and all lights stay switched off when the buttons are pressed or when I unplug the inputs on Pin2 and Pin4.
And after that I wired the Classic relay, which I command with signal from car and connect the ground on arduino pin2/pin4 and the blinker/reverse light start work, normally.
Ok, I will draw diagrams for all wiring, in one hour.
and this wiring do not work.

