Registration Notice

Due to increased spam, forum registration must be manually approved by a moderator! Please see this post for instructions.

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #15 on: May 21, 2023, 02:54:04 PM »
Hi Rongyos, thanks for the question, and don't worry, your English is very good. I understand clearly what you are asking.

I've made some updates to the firmware to incorporate your suggestion. You will have to update both OP Config and also re-flash the latest firmware to your TCB (the latest version of both is 0.93.75)

To enable this feature there is an option on the "Lights & IO" tab of OP Config that you can select, called "Flicker Headlights during Engine Start."

The length of time that the flickering effect will last is defined by the "Transmission Engage Delay" setting on the "Driving" tab of OP Config. Since this setting should be set to the length of time of your engine start sound, it will also work for the flickering.

The flickering will affect both the headlights and the brake lights, but only if you have them on before you start the engine. In the case of brake lights, probably the only way for them to be on before the engine is started is to select the "Brake Lights On when Stopped" option on the Lights & IO tab.

The headlight output on the TCB is unable to be dimmed, it can only be full on or full off. However the brake lights output can be set to any intensity. I've used a slightly different approach on each one, the brake light will flicker in sync with the headlights but because it is able to be dimmed I've used that to make the flickering a little less harsh.

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.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #16 on: May 22, 2023, 08:19:17 AM »
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.

Hi Luke,

First of all, thank you for your quick reply and support.
I downloaded the new firmware and OP Config, managed to set up the build. I faced some bug / error:
  • Light toggle on/off function not working properly on headlights (see video) - its working well with toggle on + toggle off functions binded on 2 pos switch
  • Start engine flickering not working with toggle on/off function at all
  • Start engine flickering has some errors:
    • a. only works with 2 pos function
    • b. no lights at all during the start engine sequence
    • c. random light sound played during the start engine sequence

maybe there are more dependencies than I thought :( I attached a video for better understanding.

The build is up and I am happy to test the upgrades :)

Rongyos

driving_20230522.PNG
Ideas for the OP Config driving_20230522.PNG
Views: 4750
functions_20230522.PNG
Ideas for the OP Config functions_20230522.PNG
Views: 2765
lights_20230522.PNG
Ideas for the OP Config lights_20230522.PNG
Views: 2351

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #17 on: May 22, 2023, 03:30:06 PM »
Hi Rongyos, thank you very much for doing that test. In fact I see now there were multiple problems with the code I had written. It's always more complicated than it seems, and you're absolutely right, there are more dependencies than even I can remember!  ;)

But your test helped me find the problems. Also, in the version I posted yesterday, I hadn't implemented flickering for running lights, only brake lights. But I've added it now for both. And of course we don't want the headlight sound to be playing while we flicker the lights, so I've fixed that as well. Your 2 and 3 position switches should also hopefully now work correctly.

I've posted an update to the firmware. I am keeping the same version name, but you can still download it and overwrite what you flashed yesterday.

It's entirely possible there could still remain some bugs. I apologize I can't presently do any testing on my side, and I appreciate you being the guinea pig!

Let me know how it goes.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #18 on: May 22, 2023, 04:14:46 PM »
Let me know how it goes.

Hi Luke,

I thank you that you are dealing with it :)

Now the functions are working fine but a flickering does the led switch on and off randomly. Maybe thats why I wrote you a whole bunch of stupidity in the code.

What about if you can change this? (stolen from candle effect arduino code):
Code: [Select]
// Generate a random dimming value (0-255)
 int dimValue = [i]random(170) + 170[/i]
[i]delay(random(150))[/i];

thanks
Rongyos (the guineaPIG) :)

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #19 on: May 23, 2023, 08:06:48 AM »
Hi Rongyos, you're right, simply turning a light on and off doesn't make for a very realistic "flickering" effect. I haven't actually seen what it looks like, but I can imagine it is not very good.

Unfortunately, that is the only option we have for the headlights, which is connected to a "digital" output on the ATmega2560 chip. A "digital" output is one that can only have two states, either on or off. There are other pins on the ATmega2560 that are called "analog" outputs and those can be set to any level between off (0) and on (255). But these pins are limited in number and we have had to use them for other things.

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.

Here is the code I have added which handles the flickering. There is more than this, but this is the important part:

Code: [Select]
// 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
    }
}

I think the only other option to improve the headlight flickering would be to use the Aux output for headlights instead. The Aux output uses an analog output and therefore could be flickered more realistically. Of course this would require even more changes, and also there is no headlight sound associated with the Aux output (although one could be created with Function Triggers assigned to the same switch).

I'm not sure if the added complexity would be worth it... I may consider it but I need to explore the code some more to remind myself what complications that would involve.

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?
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #20 on: May 24, 2023, 02:14:34 PM »

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?

Hi Luke,

I attach a video how it looks. The brake light is on during enginestart sequence and no flickering on it (in the video it looks like it has but its just visual illusion, the blinking headlight effects the camera lens (beleive me pls :) )

Is the Headlight pin is PWM compatible digital pin? (analogWrite = random(150)+170)

How complicated will be to add this effect to AUX outputs if the brake light flickering will successful? It would be very good.

Thanks
Rongyos

« Last Edit: May 25, 2023, 01:42:51 AM by Rongyos »

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #21 on: May 25, 2023, 10:07:35 AM »
Hi Rongyos, thanks once again for doing this test. I apologize I'm not able to work out these bugs on my end, I only have a couple TCB boards left to me and they are in a storage box on the other side of the world!

I think I know what was wrong with the brake light effect. I've made a new firmware, this time I'm just attaching it to this message and will wait to update the official one until we have all the problems worked out. Can you test once again with the brakelight and let me know how it looks?

As for the headlight pin, no, unfortunately, that is what I was saying earlier, it is not PWM compatible. It can only be turned on or off, and I agree with you, that effect does not look very good...

It should be possible to flicker the Aux output but let's see if the effect looks good on the brake output first, because it will be the same effect on the Aux output.

*
2023_05_25_tcbmk1_TEST.hex
(321.61 kB ~ Downloads: 68)
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #22 on: May 25, 2023, 02:20:22 PM »
let's see if the effect looks good on the brake output first, because it will be the same effect on the Aux output.

Hi Luke,

Thanks for your support :) I think "we are almost there". The flickering works in the brake light but I think it only needs a "faderate", because now it changes the dim very fast.
IDK if this helps but I found a code from somewhere with fadein fadeout (it might be useless but trying to "help"):

Code: [Select]
  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);
  }


Rongyos

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #23 on: May 26, 2023, 11:00:12 AM »
I see what you mean about it being a bit harsh. I can't quite use the faderate code as written, but I've tried to soften it some more in the attached.

I think I will need to buy an Arduino and LED to do some testing at home. I've been using an online emulator but it really doesn't provide an accurate representation of what the LED will look like. 
*
2023_05_26_tcbmk1_TEST.hex
(321.62 kB ~ Downloads: 72)
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #24 on: May 26, 2023, 02:12:06 PM »
I think I will need to buy an Arduino and LED to do some testing at home.

You dont need to if I am here :)
Very, very close. I think we can meet the goal if the max flickering dim is below the max dim (255)

Something like this:

Code: [Select]
  // 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)

I dont understand the first row. Why do we need 0 (full off) state?

Here is the video. IRL its mutch better and looks like drop voltage flickering but It will be better with lower max value :)


Thanks
ROngyos

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #25 on: May 26, 2023, 03:54:02 PM »
Well I'm glad we are making progress!

To answer your question, we don't need to have full off, but that line of code could result in a full off. The random(100) means it will choose a value between 0 and 100, so it was possible that it could choose 0 (off). However the code I posted this afternoon wouldn't go to full off, but you're right, it would possibly go to full brightness.

You can try the attached version, here is the code that I am using this time. For the "dimmer" setting you can see we won't go below 50. For the "brighter" setting I took your suggestion and we won't go above 225:

Code: [Select]
    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

If you get tired of all the back and forth you could also try compiling the code in the Arduino IDE yourself, and then you could change it as much as you want until you find the perfect settings. But I'm also happy to keep making adjustments this way.
*
2023_05_26_tcbmk1_TEST_2.hex
(321.62 kB ~ Downloads: 70)
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline NS-21

  • 53
  • dreamer
    • View Profile
Re: Ideas for the OP Config
« Reply #26 on: May 26, 2023, 04:24:42 PM »
To be honest, I still can not understand the sacred meaning of these changes.

More precisely, I can’t understand what their functionality is, in application, in the construction (revival) of models.

That's what I really get - this is, for example, the functionality of flashing beacons for ships, for police cars, or just cars, so that when turning left, for example, the turn signal turns on automatically - turning left, for example.

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #27 on: May 27, 2023, 10:37:10 AM »
The idea here is that we would "flicker" the lights (an English word a little differing than flashing or blinking), during the time that the engine is starting. On old tanks (and even old cars) the current draw from the engine starter motor would reduce the battery voltage so that headlights would look dim until the engine started and the alternator began creating current. That is the effect we are trying to create here.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Ideas for the OP Config
« Reply #28 on: May 31, 2023, 04:42:40 PM »
Hi Rongyos,

I bought a cheap Arduino UNO and a couple LEDs so I could do some testing on my laptop. Here is yet another update where I've adjusted the flickering effect to be about as good as I can get it.

Other changes:
  • I've removed completely any effect on the headlight output since that simply doesn't look good.
  • But I did add the effect on the Aux output (Arduino pin 8 ). So you use that for your headlights instead. Of course the Aux output needs to be On when the engine is started or else nothing will happen.
  • The flickering effect will apply correctly now to the brake light depending on whether the brake light is on or just the running light.
  • 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.
*
2023_05_31_tcbmk1_TEST.hex
(321.88 kB ~ Downloads: 68)
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Ideas for the OP Config
« Reply #29 on: June 01, 2023, 02:18:57 PM »
    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.

    Hi Luke,

    Sorry for the late reply I was not near my computer
    Honestly, the softness on the end of the flickering is too high and not realistic now. Can you lower (much much lower it) to almost nothing?
    Also, the flickering is almost perfect and realistic. Can you add a little bit more softness? Just a little bit :) Unfortunatelly I only have TCB right now and no free arduino :(

    Regards
    Rongyos[/list]

     

    bomber-explosion