use latest one for arrow input
This commit is contained in:
@@ -13,7 +13,11 @@ int prevVal = 1;
|
||||
|
||||
struct arrow {
|
||||
int pinNumber;
|
||||
int state;
|
||||
int current;
|
||||
int prev;
|
||||
struct arrow *older;
|
||||
struct arrow *newer;
|
||||
Hat arrowSymbol;
|
||||
};
|
||||
|
||||
struct ButtonInfo {
|
||||
@@ -24,6 +28,10 @@ struct ButtonInfo {
|
||||
};
|
||||
|
||||
struct arrow arrowTable[4];
|
||||
struct arrow oldestArrow;
|
||||
struct arrow newestArrow;
|
||||
|
||||
|
||||
#define ButtonInfoTableSize 9
|
||||
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
|
||||
|
||||
@@ -71,15 +79,28 @@ void setup()
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
|
||||
arrowTable[0].pinNumber = 6;
|
||||
arrowTable[0].arrowSymbol = Hat::TOP;
|
||||
arrowTable[1].pinNumber = 7;
|
||||
arrowTable[1].arrowSymbol = Hat::LEFT;
|
||||
arrowTable[2].pinNumber = 8;
|
||||
arrowTable[2].arrowSymbol = Hat::BOTTOM;
|
||||
arrowTable[3].pinNumber = 9;
|
||||
arrowTable[3].arrowSymbol = Hat::RIGHT;
|
||||
|
||||
|
||||
|
||||
for (int i=0; i<4; i++){
|
||||
pinMode(arrowTable[i].pinNumber, INPUT_PULLUP);
|
||||
arrowTable[i].state = 1;
|
||||
arrowTable[i].older = NULL;
|
||||
arrowTable[i].newer = NULL;
|
||||
}
|
||||
|
||||
oldestArrow.older = NULL;
|
||||
oldestArrow.newer = &newestArrow;
|
||||
oldestArrow.arrowSymbol = Hat::CENTER;
|
||||
newestArrow.older = &oldestArrow;
|
||||
newestArrow.newer = NULL;
|
||||
|
||||
}
|
||||
|
||||
void handleButtonInput(ButtonInfo *but){
|
||||
@@ -114,23 +135,25 @@ void loop()
|
||||
|
||||
|
||||
for (int i=0; i<4; i++){
|
||||
arrowTable[i].state = digitalRead(arrowTable[i].pinNumber);
|
||||
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
|
||||
if(arrowTable[i].prev==1 && arrowTable[i].current==0){
|
||||
// add arrow to the tail of linked list
|
||||
arrowTable[i].older = newestArrow.older;
|
||||
arrowTable[i].newer = &newestArrow;
|
||||
newestArrow.older->newer = &(arrowTable[i]);
|
||||
newestArrow.older = &(arrowTable[i]);
|
||||
}
|
||||
else if (arrowTable[i].prev==0 && arrowTable[i].current==1){
|
||||
arrowTable[i].newer->older = arrowTable[i].older;
|
||||
arrowTable[i].older->newer = arrowTable[i].newer;
|
||||
arrowTable[i].newer = NULL;
|
||||
arrowTable[i].older = NULL;
|
||||
}
|
||||
arrowTable[i].prev = arrowTable[i].current;
|
||||
}
|
||||
|
||||
if(arrowTable[0].state == 0){
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::TOP));
|
||||
}
|
||||
else if(arrowTable[2].state == 0){
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::BOTTOM));
|
||||
}
|
||||
else if(arrowTable[1].state == 0){
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::LEFT));
|
||||
}
|
||||
else if(arrowTable[3].state == 0){
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::RIGHT));
|
||||
}
|
||||
else{
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::CENTER));
|
||||
}
|
||||
|
||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(newestArrow.older->arrowSymbol));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user