STAR Firmware by JonnyC - Source Code and Explanation

By looping through the basic modes twice (in a row, without pauses).

Hi, i’m a regular reader but is my first post in BLF.

I’m trying to make a variant of your firmware but with a lock mode.

From off: 1 extra long press of switch (i.e.10 seg) locked, and only with another 10 seg can unlock

Anybody can help me with the code. I don’t know C but try and error can modify the original code like this:

From off:

  • 1 long press 100%
  • 1 short press cycle L to H (without 0%)

From on:

  • 1 long press 0%
  • 1 short press cycle L to H (without 0%)

Thanks in advance.

Jaime.

Are you using a light with an e-switch?

If so, you might find ToyKeeper/Baton.c useful as a starting point, since it already implements a lock mode toggled by a long long press from off. However, it uses long press while on to advance modes, and short press turns the light on or off in whatever mode was last used. But it might at least be useful as a base for making what you want.

The code is in the firmware repo link in my signature.

Thanks ToyKeeper, I’m using Garrybunk.c from here Index of /torches/garrybunk and made some mods and get all what i want less locking mode and duplicate imputs and outputs.

This is the modified code. Dropbox - JAIMELITO.c - Simplify your life

The extended turbo timer and gradual ramp down you guys helped write for me have served me very well especially when used with the off time memory version.

I’m looking to take it one step further and implement STAR in some higher capacity lights I’ve been using. These lights are typically used at lower outputs for several hours at a time.

What I’m after is a global timer that would turn the light off after 5 hours.

Global in the sense that it would apply to all of the settings on the light. If low, medium, or high was left on for five hours, it would automatically turn itself off.

Is something like this feasible within STAR off time memory?

Now i’m noticied that have some flickering in direct FULL MODE with long press from off, but not for normal 255 output…
How i could fix it?

In video the first light it’s when flickering and the second full is normal cycle full.

Yes, but the timing won’t be very precise.

You should be able to count the WDT ticks in a 16-bit unsigned int. I think the default is 500ms per tick, so 36000 ticks would be about 5 hours. If the code sees the timer has gotten that high, it can turn off the light using the same method the low-voltage protection uses.

I’m talking to myself. Fixed it. I’ve remove FULL MODE and put the last mode when a LONG PRESS.

My next step is control 2 leds and 2 momentary switch with only one ATTINY13A. It’s possible with attiny13A or i need to change it?

It’s possible. The 13A has six in/out ports. However, only five of them are practical as the last one is the reset pin (PB5). Setting the reset pin to be an IO means that you will have to resort to high voltage programming in order to be able to flash the driver again. Other than that, you can do what you want with the five IOs. I think only two of them can do PWM, so these should be your LED outputs. Use two more for the E-switches, and the last you could use as a voltage monitoring input if you want.

Ok. i think to use PB0 as second led output and PB4 as second switch but my question is. Can work attiny13A with two different pwm frecuencys at the same time?

Yes, the attiny13a can do two PWM channels at once, but they share a loop counter. See the “dual PWM” section of the repository index file for a list of projects which support this, as examples of how to do it. The shared loop counter goes from 0 to 255 and each PWM channel has its own ceiling so you can control the output of each independently.

100Hz & 8kHz at the same time?

If you really want that, it’s technically possible… but the 100Hz part wouldn’t use the onboard PWM hardware. You’d have to set the 8kHz level to run automatically, then turn the 100Hz channel on and off manually with the MCU.

If you limit things to only what the dedicated PWM hardware can do, both channels must run at the same frequency. The difference between them is their duty cycle… so one can run at 100% and the other channel at 8%.

I am using STAR_dual_switch in the Yezel Y3. It has a rear clicky and a electronic side switch. So I can switch the light on with the rear clicky and than cycle trough the modes using the side switch. It has mode memory, so you can use the rear clicky to switch the light off and on and it stays in the chosen mode. It is good for signaling or morse code for example.

Now I would like to ask if this firmware can be updated with dual-PWM output because I would like to switch the driver to a FET+7135 driver.

Hi guys,
I need to modify something in the software so I figured I ask here.

I have a headlamp with a XM-L led. The driver is on the back of the head in the battery case.
The lamp has a momentary switch on the back of the led housing. This way there are 3 wires running from the led to the battery case. When I press the button the 3rd wire (the control) goes to LED ground thus pulling low the control pin on the controller.
Now, stock driver is crap and I designed my own using 9xAMC7135 and attiny.
The issue is that AMC7135 is on the - side of the LED thus the ground being unconnected when the light is off. This means that I have no way of pulling the controller leg low.
So now I have two options. Replace (once again) the wiring going to the LED and another wire for a total of 4, or modifying the software so I can pull the pin high on the controller. The LED+ wire is live all the time and I can mod the internal connections of the button.
What would I need to modify in the firmware to pull the pin high instead of low?
After some breadboard tests I found that pin 2 (PB3) must be pulled low with stock firmware.
Thank you.

Er, I’m not entirely sure if you just answered your own question or not.

The attiny can tell you if a pin is grounded or not, and you can reverse the interpretation of that if necessary… I think it just requires switching some 1s and 0s or putting a logical “not” operator in a few lines. I can’t really answer much about the hardware level of the issue though.

For me it would be easier to just edit the code and choose pull-up instead of pull-down as a matter of state detection.
That way I would not need to mess with the wires. But I provisioned my pcb for both cases where I added an extra resistor in line with the button wire.

I’d like to know where and how should I alter the code for what I need.

DIDR0 |= (1<<ADC3D); // Disables digital input on PB3. Not really needed, but saves power.

DDRB |= (1 << PB3); // Sets PB3 as output.
PORTB |= (1 << PB3); // Sets PB3 high.

Great, thank you!
I will test it tonight when I get home.

That was configuring the pin as output and setting it high. It might be worth trying to keep it as input but activate the pull-up resistor.

From the datasheet: “If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated.”
To do that you just use the last line in my above example because the initial DDRB values are already 0:

PORTB |= (1 << PB3);

I haven’t use IOs the way you need to in this case so I can’t say it will work. At least you have a couple of things to try.