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)
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.
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?
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.
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.
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.
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.