DDRB=2; PORTB=8; //define PB1 as output and pull-up switch on PB3
I have one with the switch wired to the third star/PB4 but the wire's hidden under JB Weld (d'oh!), what does that line need to be changed to to switch the input pin from PB3 to PB4? I tried random numbers, but couldn't get it to work. (I temporarily rednecked it by bridging pins 2 & 3 with solder) xD
have you considered soliciting/accepting ‘donations’ from those who use the code?
I just bought a few drivers and I’m planning to use your firmware. Rather than purchase drivers from you, I’m forcing myself to learn how to flash them, with an eye toward eventually learning to modify the code…….but I have no problem compensating you for your ingenuity.
Another reason for doing it myself - I’m having a little trouble deciding which firmware to use (from just reading the text descriptions), so I want to experiment with each. I might also draw flow diagrams for your UIs at some point.
Anyone know what pins are the momentary switch? I can pull up the Attiny13a data sheet and compare it to the code, but I'm hoping someone already knows.
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.