Firmware for -Attiny85- to control 2 led with momentary buttons independently

Toykeeper is a big help, but you may be better off just posting in this thread. It is the go-to place for firmware questions and answers.

I personally have used a very similar firmware (based on STAR) but it does not have the lockout feature.

This is my scheme and the housing of the headlamp

This is that i have

Where are you getting the housing fabricated?

In a local milling lathe company.

Ahh ok. I am also designing a headlight and will be designing the casing for it. It’s a slightly different type of light though: Build: Dual XP-L headlight project.

I can’t help you much with your code, I did all that differently. Your code uses E-switch activated interrupts, I don’t. I run the watchdog interrupt at highest speed and do all E-switch checking in the main() routine. Besides the E-switch my light also has a mechanical switch with an off time capacitor, so I have a lot of functionality on that.

This is my try of duplicate but can’t build solution.

I’ve solved the problem of can’t build but doesn’t work only get fix low mode and anymore…

It’s nearly full the tiny13a (99.6%) therefore I change for a tiny85.

Can anybody help me.

Well, my attiny85 it’s down. But I’m useing Proteus for the simulation-test of code.

Anybody can help me? I’m stuck in this like two months :weary:

hello, anybody here???

I’m stuck in firmware development :_(

I think timing is why you are not getting FW responses. We have less than a handful of capable programmers right now and they all seem to be deep into developing their own FW's for the Attiny85. They all have normal jobs and limited hobby time to do that. Just seems to be a lot going on right now on that front.

Hang in there and keep plugging away. Sounds like an interesting project.

Please explain that timming problem.


I could maybe help, but need more details:

  • what is the goal for hardware. You say 2 LEDs, and momentary buttons, like plural - what does this mean? Do you want two separate PWM output channels and 2 electronic buttons?
  • I'm not sure what you mean by "locked" or "unlocked". Please explain. There's lots of ways that can be interpreted.

1st thing is you say it's for an 85 but you have the F_CPU set to 4.8 Mhz? I only got 8 Mhz working on a 85. 4.8 is the speed for a 13A, not an 85.

Also you are not providing fuse settings -- please provide what you are using. I have no clue what Proteus is - sounds like a simulator. I only have experience working directly with 85's. Not sure if I can help you out much if you are not using the real thing.

I'm looking at the code while typing this post....

I do see you have the 2 PWM's configured - good, and the 2 switch's configures on pin's 2 and 3 of the CPU - think that is good too. You setup the next/prev in duplicate, which indicates you want 1 button controlling 1 LED, and the other button controlling the other LED - I understand better what you are trying to do... Still look'n/reviewing....


Looks like there's some confusing things goin on:

  • indentation is confusing - difficult to follow. used a "beautify" tool to clean it up so I could review it
  • FULL_MODE ?? checked for but never set?
  • what is goin on with strobe mode? It's implying you think it's mode_idx set to 4, but in your 'modes' table, mode_idx of 4 is hi (255 value) ??
  • also, looks like you only check the 2nd button mode changes if the 1st button mode change occurred. Not sure if that's what you want? Doesn't sound right.

hope some of this helps.. Might be missing something, but run out of time - probably for rest of day.

I think it is better to explain how I want it works.

My intention is control each led independiently.

There are 4 modes 2,32,125,255.

From OFF.

  1. Short press turn on in first mode
  1. Long press turn on in 255 mode.

From ON.

  1. Short press change to next mode ascending.
    cycling beetwen modes without pass for 0.
  1. Long press turn led off

I get this working with 1 led and 1 momentary but when I try to duplicate the code for useing 2 led and 2 momentary it doesn´t work.

I can’t test with real attiny85 because I have a bad fuse config with the only one I have. I’m using Proteus(simulation electronics program) until get some new Tiny85

k - when u say doesn't work, LED #1 stops working or just LED #2 doesn't work? By doesn't work, give me all the specific details...

It's always best to take baby steps first, small incremental changes, specially when we can't single step debug. Sounds like you did that to some extent.

Still dunno how you want the 2nd switch to work. Looks lts tied to the 1st switch the way you wrote the code. The code you wrote doesn't independently handle the 2nd switch. Check your braces in the main loop. You are only checking for a mode change for LED #2 when and only when a mode change occurs with LED #1.

thats correct led 1 stop working stay fix in lower level and led 2 doesn’t turn on.

The problem is that I’m trying to learn C but all the manuals that I found was using diferent syntax.

with 1 led the program runs perfect.


This is with tiny13 it’s the only physical avr that I have at the moment.

k, this line of code is wrong for qualifying sleep mode:

if (real_mode_idx && real_mode_idx2 == 0){

I think you want this:

if ((real_mode_idx == 0) && (real_mode_idx2 == 0 ) ){

And again - I think your main loop is wrong(?) You probably want to check the change of modes for each switch independently?

Thanks for the correction and yes, I want each switch independently. This is for a headlamp with a flood led and a throw led for caving.

I need to adjust the mode of each led independently .

now it fixed in pastebin code.

I’ll simulate in proteus.

well, still not working. In simulator when I burn 1Led code it works perfect too.

But when burn 2 Led code.

pushing PB3 then the PB1 get fixed in 0,9v (85/255) and doesn’t respond anymore I need to reset.

Wait - what is that "return 0" doing in the main while loop? That's not good being there. Looks like the first mode change would cause the light to get stuck permanently on in that mode... Hhmm. Check it out.

My code at the end of main looks like this:

} // mode change detected
} // while

return 0; // Standard Return Code

If you comment the close curly braces like above, it helps tracing down the indents.