David_
Advanced Member level 2
Hello.
I have posted on the arduino forum about this subject since I am using arduino but so far I have no replies and I have not solved it my self jet, I bought a couple of encoders from sparkfun: https://www.sparkfun.com/products/10982
They have RGB diodes and a switch besides the encoder and I am planing to use the encoder for my lab power supply to use the RGB diodes to signal things like reaching the current limit(flashes red maybe) while steadily shinning green while all is well and the output is active etc etc
While using the switch/button to change the steps in voltage/current each step of the encoder represents(double click) or/also using the button to select option on the menu while navigating it through turning the encoder right/left(single click).
Prototype with hardware de-bouncing which is not enough for the switch:
**broken link removed**
Or something similar, that is not happening until I figure out how to do those things but I lack the programming skills as will show below. I have spent many hours on this and trying to write a class for the encoder but it has failed.
I don't want to be polling the switch and I use a external interrupt detecting rising edges( the button is internally connected to the supply voltage), a double click needs to be within 600mS within the first click and to make a click and hold the hold time needs to exceed 1200mS.
I am not experienced with programming and it is not a subject very suitable for me but I really try to develop in it.
My interrupt ISR is called switchAction() and the latest attempt looks like this:
This might be a very ugly way of doing it I don't know but I could really need some assistance.
Regards
I have posted on the arduino forum about this subject since I am using arduino but so far I have no replies and I have not solved it my self jet, I bought a couple of encoders from sparkfun: https://www.sparkfun.com/products/10982
They have RGB diodes and a switch besides the encoder and I am planing to use the encoder for my lab power supply to use the RGB diodes to signal things like reaching the current limit(flashes red maybe) while steadily shinning green while all is well and the output is active etc etc
While using the switch/button to change the steps in voltage/current each step of the encoder represents(double click) or/also using the button to select option on the menu while navigating it through turning the encoder right/left(single click).
Prototype with hardware de-bouncing which is not enough for the switch:
**broken link removed**
Or something similar, that is not happening until I figure out how to do those things but I lack the programming skills as will show below. I have spent many hours on this and trying to write a class for the encoder but it has failed.
I don't want to be polling the switch and I use a external interrupt detecting rising edges( the button is internally connected to the supply voltage), a double click needs to be within 600mS within the first click and to make a click and hold the hold time needs to exceed 1200mS.
I am not experienced with programming and it is not a subject very suitable for me but I really try to develop in it.
My interrupt ISR is called switchAction() and the latest attempt looks like this:
Code:
void switchAction()
{
unsigned long T = micros; // Will not update while in ISR.
static unsigned long oldT = 0; // Will store T for next interrupt.
static uint8_t clickCount; // A try to track if its first or second click.
unsigned long repeatInterval = oldT - T; // Used to check if a click is within 600ms/60000µS.
if(clickCount > 0 | repeatInterval < 60000)
{
doubleClick();
clickCount = 0;
}
else if(clickCount != 1)
{
if (T - oldT < 10000) // De-bounce
{
}
else
{
if(hold time is les than 1200mS) // This should determine if the switch is hold or not.
{
singleClick();
clickCount = 1;
}
else if(hold time is more than 1200mS) // Should determine if switch is hold or not.
{
clickAndHold();
}
}
oldT = T; // Store time for next time through ISR.
}
This might be a very ugly way of doing it I don't know but I could really need some assistance.
Regards