This is some untested code that may give you some ideas. Given that you'll probably want some debouncing even for a single press the approach is to keep shifting eight readings through a byte so that you have a record of the last 8 readings. Then where the MSB is set it counts the number the number of times in those samples that 2-4 ones occur in a row and treats them as a click, two such occurrences are treated as a double-click.
You may need to play around with the sample rate and those numbers to suit your input device, and as mentioned it's untested but it may give you an idea on a way to go about it.
int readButton(int button) {
b0 = bitRead(button,0);
b1 = bitRead(button,1);
b2 = bitRead(button,2);
digitalWrite(10,b0);
digitalWrite(9,b1);
digitalWrite(8,b2);
if (digitalRead(buttonPin) == HIGH)
return 1;
else
return 0;
}
// Perform following in timer or at a fixed interval
// Keep a list of the last 8 button states, LSB is most recent
for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
buttonValue[buttonCount] <<= 1;
buttonValue[buttonCount] |= readButton(buttonCount);
if (buttonValue[buttonCount] & 0x80) {
int onCount = 0, clickCount = 0;
for (int bitPos = 0; bitPos < 8; bitPos++) {
if (buttonValue[buttonCount] << bitPos & 1)
onCount++;
else {
// Treat 2-4 readings in a row as a click
if ((onCount >= 2) && (onCount <= 4))
clickCount++;
onCount = 0;
}
}
if (clickCount > 0)
{
if (clickCount == 1)
singleClick(buttonCount);
else
doubleClick(buttonCount);
buttonValue[buttonCount] = 0;
}
}
}