Okay. I used your code and modified it for all of the hand gestures I want to use in my wearable computer. Anything wrong?
int gesture[4];
int inputMatchupRightClick[4] = {HIGH, LOW, HIGH, HIGH};
int inputMatchupLeftClick[4] = {LOW, HIGH, HIGH, HIGH};
int inputMatchupSpace[4] = {HIGH, HIGH, LOW, HIGH};
int inputMatchupEnter[4] = {HIGH, LOW, LOW, HIGH};
int inputMatchupCaps[4] = {LOW, LOW, HIGH, HIGH};
boolean matches(int a[4], int b[4])
{
for (int i = 0; i < 4; i++)
if (a[i] != b[i])
return false;
return true;
}
void setup()
{
Serial.begin(9600);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
}
void loop()
{
static unsigned long lastUnmatchTime = 0;
gesture[0] = digitalRead(3);
gesture[1] = digitalRead(4);
gesture[2] = digitalRead(5);
gesture[3] = digitalRead(6);
if (matches(gesture, inputMatchupRightClick))
{
if (millis() - lastUnmatchTime >= 50)
{
Serial.println("right click detected");
}
}
else if (matches(gesture, inputMatchupLeftClick)
{
if (millis() - lastUnmatchTime >= 50)
{
Serial.println("left click detected");
}
}
else if (matches(gesture, inputMatchupSpace)
{
if (millis() - lastUnmatchTime >= 60)
{
Serial.println("space detected");
}
}
else if (matches(gesture, inputMatchupEnter)
{
if (millis() - lastUnmatchTime >= 60)
{
Serial.println("enter detected");
}
}
else if (matches(gesture, inputMatchupCaps)
{
if (millis() - lastUnmatchTime >= 60)
{
Serial.println("caps detected");
}
}
else{
lastUnmatchTime = millis();
}
}