MiniMo - simple firmware for momentary (electronic) switches (source code)

Thank you DrJones for the code!

Do I understand correctly - If I want to get rid of last mode memory and make the light always start on certain mode, I should change the code something like this:

if (mode>0) mode=0;          //was on?  -> off
else mode=2;                      //was off? -> on, start on Med

(might also skip the “lastmode” variable in the definitions)

Right?

comfychair: For a switch on PB4 use "PORTB=16;" there and "if ((PINB&16)==0)" some lines below.

AlexTG: Yes, exactly.

BTW: The minimum value of 5 in the modes[] is a quite safe value for an AMC7135-based driver; 4 might work, too. For drivers with a FET or a buck driver, even lower values may work.

Thank you Sirius9.

Yep, the low-low values 1 2 & 3 didn't work with 7135s when I tried it, only starts to light up at 4. But on the FET drivers even 1 works fine.

Dear DrJones,
Thanks for your sharing of the code.
If I understand correctly that mode=1 -> 8, mode=2 90, mode=3>255. I mean the position of the PWM levels in the line uint8_t modes={0, 8,90,255}; Am I correct?

Yep. Compare that line in the original to this one: http://75.65.123.78/fw/minimo-7mode-pb4.txt

You can also switch it to descending instead of ascending. {0,8,90,255} vs. {0,255,90,8}.

Thanx Doc. I added some simple debouncing, sped up the long click a little (350 msecs), and am using these modes:

const byte modes[]={0, 5, 10, 81, 255 }; // 5=moonlight(2%), 10=4%, 81=32%, 255=100%

The debouncing is below. It just does 3 reads on the I/O pin with a 2 msec delay in between. I'm really not sure if it will do much because no idea if the time delay of 2 msecs is relevant with this hardware. I've seen other driver code that did much longer time delays, interrupt based.

// Do some simple de-bouncing checks
byte inPressed = ((PINB&8) == 0); // 0=not pressed
if (inPressed)
{
_delay_ms (2);
inPressed = ((PINB&8) == 0);
if (inPressed)
{
_delay_ms (2);
inPressed = ((PINB&8) == 0);
}
}

if (inPressed) // qualified button being pressed

...


This firmware seems to be working fine, but I tried it in my troublesome XP-11, and high mode is not working, but had the same problem with another e-switch version (Werner's), so thinking I might have messed up the LED or driver... I think I did have a short going in with the emitter, fixed it, but damage is probably done.

Sub-moonlight with PWM of '1', after adding a big fat toroid inline with LED+...

I like these direct drive FETs much much better than 7135s.

Sweet Comfy. For some reason that fat toroidal inductor reminds me of a slicks on the back of a rear wheel drive dragster.

you’re a star DrJones and thank you for having the courage to put your hard work out there, with nothing but thanks in return. I’ve been fretting about how to turn one of my commuter lights into an e-switch light as it’s out of action due to a crappy Judco switch and this pops up. Thank you so much, it’s much appreciated.

Edited first post to add a "Werner's UI" variant of MiniMo.

Awesome update DrJones...thanks

I haven’t read this thread before. Thank you for sharing the results all your effort here for free. I’m planning to mod a light with an electronic switch, but I don’t have equipment nor knowledge to flash it myself, so I’ll take the easy route (buying one from you)
Thanks

Dear Dr. Jones,
I am thinking that the code of MiniMo is small in size which may be possible to fit in the smallest Attiny family Attiny10. I modified the code ( change PORTB=8 to PORTB=4, (PINB&8) to (PINB&4) ) to set the PB2 of the Attiny10 as switch pin and then built the hex by AVR Studio 4 but the process was failed with 2 errors. Would you please help me to correct the errors.

After I have installed the AVR-toolchain-3.4.2, the hex file can be built now.

Sorry I was of no help, but I never worked with an ATtiny10. No EEPROM and different programming interface made me not investigating them further.

Thanks for your advice. I found that the Attiny13A-MMU has the same footprint as Attiny10. It is not worth for the effort to work with an Attiny10 to replace Attiny13A.

My XP-11 just arrived and this is my first time doing this so I need some help :slight_smile:

I just want to change in this firmware short press to be “ON/OFF” and long press to be for “next mode”.

Is it enough to switch the values in these two lines:

 if (count==16) {                    //pressed long (8*50ms)

 if (count<16 && mode>0) {           //really was a short press AND the light is on

I loaded the minimo into Atmel Studio av6.2.1153 and compiled a direct copy of the code (1st one in post 1). I got 2 errors

and responded with:

I suspect this is not the right response but it corrected the 2 identical errors.
Thought I would report this FYI.

Argh... That happened when I added the up&down variant, recognized that lastmode wasn't used there, but deletetd it in the wrong code...

Corrected, thanks!

Also changed license to CC.