Help me finish the D01!!! Firmware issue.

Ok, so I added the tail switch to my D01 and modded STAR Momentary to these modes…

#define MODES 1,39,150,255 // Must be low to high, and must start with 0
#define ALT_MODES 255,255,255,255 // Must be low to high, and must start with 0, the defines the level for the secondary output. Comment out if no secondary output
#define MODE_PWM PHASE,FAST,FAST,PHASE // Define one per mode above. 0 tells the light to go to sleep

When I turn the light on via the tailcap switch, I still have to hit the momentary button to wake it up. After that it cycles through the modes fine and the tail cap of course shuts it off. What am I missing? I really wanted to hit the tailcap to turn it on in low and the cycle the modes… With the 0 levels gone, should not the cpu boot and give me the lowest mode with out a side button press?

Thanks Matt

Have you verified that mode level 1 actually produces light? It might be a little too low. Do a test run with a much higher value.

You say start with 0, that does not read like a lot of light

Can I see pics of the tail switch?
Would really like to do that myself

I have not nailed down the exact modes yet, but the mode 1 is on the FET and the mode 255 is on the 7135 and it does produce a decent amount of light with those settings. This really is a dual channel driver, I almost always build a light with a single 7135 included so there is full regulation in at least 1 mode. The final version will likely have 0 for the FET and 255 for the 7135 in the first mode slot.

Thanks Guys, I have defined modes to low a few times for the first mode. Normal lights always get the lowest low possible for the first mode, usually somewhere between 4 and 7 for the 7135 and 0 for the FET. This light will be different, ML is useless on this light with the big doughnut hole from a dedomed LED and a giant reflector.

STAR momentary is structured to start as off, regardless of the mode list. Just before the while(1) loop, where you see:


uint8_t last_mode_idx = 0;

remove the first line and change the second to initialize last_mode_idx to 1 instead of 0. Then, inside the loop, change this:

    if (mode_idx > 0) {
        // No need to change the mode if we are just turning the light off
        // Check if the PWM mode is different
        if (mode_pwm[last_mode_idx] != mode_pwm[mode_idx]) {

To just:


and I think you'll get what you want.

^ Best username for a post like this!

Actually, on further thought, be careful with removing the ‘off’ mode as the low voltage shutdown code depends on it being first in the list. STAR dual switch seems to have essentially the same problem. You’ll get step down but the step “down” from the lowest mode will be turbo instead of off! I’ve been working on those so I’ll add that to the list of things to do.

I have a modified version of STAR momentary that always comes on high when power is applied. It was for an X6R that I did. It’s probably posted somewhere here on BLF, but I’ll try to find it on my computer at home.

Guys… thanks for all the info. The hardware is pretty easy for me, but I am still muddling around the code. I have time in arduino and pi code, but not extensive.

I would like low battery rampdown to work, but I would consider it mostly working if it ramped down from high to something lower, because I do not normally let my batteries drain way low. And it would provide visual indication that I needed to charge them.

I really think a 0 mode is redundant with the tailswitch. Maybe it could be converted to “sleep the MCU” rather than 0 PWM the output. I would think both would have the same result… Maybe not? Maybe it is possible to place a trigger on an ADC reading and jump out of the standard mode orders and drop to a special or hidden mode that would normally not be in play. Maybe 7135 with PWM 50 or so.

I wanted to really dive into some of this code over winter, just did not happen with kids and life. I learn best by self-immersion into something for a few days.


Of course it is. I was just pointing out that the low voltage protection currently depends on that mode being there. I’ve already modified that code for pilotdog68’s driver so I’ll try fixing that as well at some point.

I know what you mean. Everything else seems to happen at a very slow pace when you throw kids into the mix. It must have taken me at least 2 weeks just to connect my programming clip and open up a flashlight to test it.

@fixed it, I am 50 and my girls are 9 and 13. I swear that life just rolls by me and giggles as it goes. I am going to make time to spend with that code this evening. Not sure if I will gain any ground, or not. I am a network engineer by trade and have been for almost 30 years, staying up with my field is so time consuming and feels overwhelming at times. Flashlights and firearms are my time to hide and not think about life, much. :slight_smile:

With these changes the code compiles, but the light will not turn on…

Just for giggles, I compiled the Star dual switch and it works! It is only a single pwm channel, so I am not getting the 7135 fired up. I am not sure if at this point it would be easier to convert it to dual channel or convert dual channel to dual switch? Or, I could just ignore the fact that the 7135 is there.

Can you please post that here when you find it? For some uses that is exactly what I want. Will bookmark it for the future when I get this far along in modding! I’m beginning to learn from reading the programming threads though coding is still way over my head. I just usually stay quiet on these threads since I can’t add anything useful yet.


Ah, yes. I see now that some of the initialization is (was) done in the sleep_until_switch_press() function. No quick hack apparently. It would leave you with a non-working switch but I still don’t see why it wouldn’t turn on… as long as you still use the MODES values you posted originally (the first two must be different). Adding a WDT_on() call where you removed sleep_until_switch_press() should at least fix the switch.

I think adding the second channel is easier but that might just be because it’s what I’ve worked on.