I don't actually have a TCB to do any tests with, so I can't say exactly how good it will look. I'd appreciate if you could test it both to make sure it works as intended and also to let me know what you think of the flickering.
Let me know how it goes.
// Generate a random dimming value (0-255) int dimValue = [i]random(170) + 170[/i][i]delay(random(150))[/i];
// This effect takes place on engine startup if the user has selected the option to "Flicker Headlights on Engine Start" (Lights & IO tab of OP Config) // and if they have specified a "Transmission Engage Delay" (Driving tab of OP Config). The effect will last for the duration of the Transmission Engage Delay. // It applies to both the headlights and the brake/running lights, but only if they were already on before the effect begins. void FlickerLights(){ static boolean flickerState; // Initialize if appropriate: if (HeadlightsFlickering == false && BrakeLightsFlickering == false) // They will both be false if we have not started the effect. { // They will both remain false if neither the headlights or brakelights are on, in which case we won't come back here. // Only flicker lights that are already on if (Light1State) HeadlightsFlickering = true; if (BrakeLightsActive || RunningLightsActive) BrakeLightsFlickering = true; if (HeadlightsFlickering || BrakeLightsFlickering) flickerState = false; // Initialize light state to false (which has the effect of starting the effect with "on") } // Now perfrom the flickering if it has been enabled if (HeadlightsFlickering || BrakeLightsFlickering) { if (HeadlightsFlickering) { // The headlight output can not be dimmed, so we simply toggle it on and off. // We don't use the dedicated Light1Toggle function because that would also call the headlight sound, which we don't want, not to mention the possible debug message. flickerState ? digitalWrite(pin_Light1, LOW) : digitalWrite(pin_Light1, HIGH); } if (BrakeLightsFlickering) { // The brake light flickering effect will differ depending on whether we are flickering the running lights or the full brake lights. if (BrakeLightsActive) { // Here we vary the light between some lower and higher dim levels, it can go full off or full on, but also something in-between if (flickerState) analogWrite(pin_Brakelights, random(100)); // Dimmer - random value between 0 (off) and 100 (not even half brightness) else analogWrite(pin_Brakelights, random(75)+180); // Brighter - random value between 180 and 255 (full on) } else if (RunningLightsActive) { // Here we vary the light between full off and whatever the running lights dim level is flickerState ? digitalWrite(pin_Brakelights, LOW) : analogWrite(pin_Brakelights, RunningLightsDimLevel); } } // Toggle the flicker state, now it will match what we've just done above (which was the opposite of flickerState) flickerState = !flickerState; // Now set a timer to come back here after a random amount of time to continue the effect // We adjust the random delay so that the light "off" time is shorter than the light "on" time if (flickerState) FlickeringTimerID = timer.setTimeout(random(350)+60, FlickerLights); // On - random time between 60 and 410 mS else FlickeringTimerID = timer.setTimeout(random(210)+50, FlickerLights); // Off - random time between 50 and 260 mS }}
The brake light is connected to an analog output which is how we are able to dim it for "running lights." If you set the "Brake Lights on When Stopped" option you will see that it uses a flickering effect similar to the candle effect you found. But when we are flickering the "running lights" I can't be sure what dim level the user specified, and to flicker a dim light it might not be very visible, so in that case I am flickering it only between off and the dim level. [...]In the meantime, maybe you could attach a white led to the Brake lights, and select the "Brake Lights on When Stopped" option, and then at least let me know if that effect even looks very good?
let's see if the effect looks good on the brake output first, because it will be the same effect on the Aux output.
int brightness = random(256); // Fade in for (int fadeValue = 0; fadeValue <= brightness; fadeValue += 5) { analogWrite(ledPin, fadeValue); delay(10); } // Fade out for (int fadeValue = brightness; fadeValue >= 0; fadeValue -= 5) { analogWrite(ledPin, fadeValue); delay(10); }
I think I will need to buy an Arduino and LED to do some testing at home.
// Here we vary the light between some lower and higher dim levels, it can go full off or full on, but also something in-between if (flickerState) analogWrite(pin_Brakelights, random(100)); // Dimmer - random value between 0 (off) and 100 (not even half brightness) else analogWrite(pin_Brakelights, [u]random(45)[/u]+180); // Brighter - random value between 180 and 255 (full on)
if (flickerState) analogWrite(pin_Brakelights, random(70)+50); // Dimmer - random value between 50 and 120 else analogWrite(pin_Brakelights, random(45)+180); // Brighter - random value between 180 and 225
Hi Rongyos, When the flickering is finished (the transmission engage delay has expired/your engine start sound has finished), the lights will gradually return to full brightness instead of doing so abruptly all at one.You can let me know what you think.