STAR Firmware by JonnyC - Source Code and Explanation

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.

I tried everything I could and it’s not working.
So here’s the relevant bit of code:

Couldn’t make it work.
It says “0 being low for pressed, 1 for pulled-up for released”. 0 is pressed in default config. So I need 1 for pressed.
The pull-up resistor is high because:

So I don’t need to do it.
Now, there’s something with the underlined bit of code. I need to reverse the way it registers the push signal. From low to high.

I don’t know if or how that can be done.

You need to add a pull-down resistor to keep the line normally low, then pressing the switch will pull the line high. Any value from 1k to 100k can be used if you disable the pull-up resistor on that input. But using a 1k ohm pull-down will overcome the internal pull-up even if not disabled (at the expense of a fraction of a Milli-amp of extra current draw, this could be an issue with e-switch lights). It is important that the positive side of the switch is the same voltage as the controller IC. If the voltage is higher, the IC may be damaged.

I'm not sure about the code, firmware wigs me out, I'm always off by one...

First try adding the pull-down resistor, then revisit the code, it just may work!

Edit: Put a meter on that line and verify it goes from a zero to a one when the switch is pressed.

Keep us posted.

Where I can find the “optimize for size”-option in Atmel Studio? At the moment my hex file is to large for the Attiny13A :frowning:

On the File menu at the top of your screen click “Project”, click the bottom selection “(project name) Properties”, click “Toolchain” on the left, and look for “Optimization”. Optimization level set to -Os Optimize for size.

Hi all,

Is the clickie version of this firmware default to use on time or off time memory?

The basic clicky STAR uses on-time. STAR_noinit uses fixed offtime via a memory decay trick. Or STAR_offtime uses configurable offtime via an offtime capacitor. Take your pick.

Ok, for the STAR_noinit. You say this uses a "decay trick". Does that mean that I can use that with a nanjg 105C and it will give the board off time memory?

I have a version of wights single sided 17mm FET DD board I would like to use it on. It has an OTC with a value of 1uf. I am guessing the STAR_offtime would be the way to go with that?

Yes & yes. You got it right. :)

Thank you! Flash Size is 0.94 KB (972 Bytes) now. That should work?

yeah should be fine. when you flash you should see exactly the size being written to the attiny. I think it’s 1024 bytes max.

Ok, I seem to be having some trouble with the Star offtime. I assume this is the one I am suppose to be using for the FET driver?

~toykeeper/flashlight-firmware/trunk : contents of JonnyC/STAR/STAR_off_time/STAR_off_time.c at revision 249



Even using the code as is, I am not able to get it to build correctly. At least I dont think I am. It says 0 errors but 5 warnings

Warning 1 unused variable 'prev_mode_idx' [-Wunused-variable] line 366

Then for lines 192,186,183, and 177 I get this warning over and over.

Warning 2 'modes' is static but used in inline function 'check_stars' which is not static [enabled by default]

What should I do about this?

someone who knows more can chime in but I’m pretty sure I had those warnings and it worked fine. flash it and test it :beer:

Yes, that's the correct one.

0 errors means that it compiled "correctly".

Those warnings are not severe, so you can just ignore them.

Or fix them by:
- removing the line 366 (the variable is not used, so it can - and should be - removed safely)
- removing the 'inline'-definition on line 168 (no point of inlining that function, especially as it uses a static variable which kind of works, but violates the C-standard)

Ok, Thanks.


I have a couple more questions. I would like to know how to add more modes to this.

I saw that the high mode was disabled, so I enabled that and added a value, but I would also like to be able to add more.

For example can I have the moonlight mode enabled by default rather than when using star 2?

Also if I wanted to get even more modes than that, like say 6,7,8 in the string, how to do that?

Other frimwares I have seen just had them in a single line like "define modes, 0,2,7,14,39,100" etc, but this one has a define and the name of each one.