rewrite button definition
This commit is contained in:
@@ -16,16 +16,17 @@ struct arrow {
|
|||||||
int state;
|
int state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct button {
|
struct ButtonInfo {
|
||||||
int pinNumber;
|
int pinNumber;
|
||||||
bool prev;
|
bool prev;
|
||||||
bool current;
|
bool current;
|
||||||
|
Button buttonSymbol;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct arrow arrowTable[4];
|
struct arrow arrowTable[4];
|
||||||
|
#define ButtonInfoTableSize 2
|
||||||
|
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
|
||||||
|
|
||||||
struct button bButton;
|
|
||||||
struct button plusButton;
|
|
||||||
|
|
||||||
void perms() {
|
void perms() {
|
||||||
if(val == 0){
|
if(val == 0){
|
||||||
@@ -51,6 +52,14 @@ void button() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol) {
|
||||||
|
but->pinNumber = pinNumber;
|
||||||
|
but->buttonSymbol = buttonSymbol;
|
||||||
|
pinMode(pinNumber, INPUT_PULLUP);
|
||||||
|
but->prev = 1;
|
||||||
|
but->current = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
table[0] = 1;
|
table[0] = 1;
|
||||||
@@ -60,6 +69,10 @@ void setup()
|
|||||||
MsTimer2::set(1, perms);
|
MsTimer2::set(1, perms);
|
||||||
MsTimer2::start();
|
MsTimer2::start();
|
||||||
|
|
||||||
|
setupButton(&(buttonInfoTable[0]), 3, Button::B);
|
||||||
|
setupButton(&(buttonInfoTable[1]), 15, Button::PLUS);
|
||||||
|
|
||||||
|
/*
|
||||||
bButton.pinNumber = 3;
|
bButton.pinNumber = 3;
|
||||||
pinMode(bButton.pinNumber, INPUT_PULLUP);
|
pinMode(bButton.pinNumber, INPUT_PULLUP);
|
||||||
bButton.prev = 1;
|
bButton.prev = 1;
|
||||||
@@ -69,7 +82,7 @@ void setup()
|
|||||||
pinMode(plusButton.pinNumber, INPUT_PULLUP);
|
pinMode(plusButton.pinNumber, INPUT_PULLUP);
|
||||||
plusButton.prev = 1;
|
plusButton.prev = 1;
|
||||||
plusButton.current = 1;
|
plusButton.current = 1;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
pinMode(2, INPUT_PULLUP);
|
pinMode(2, INPUT_PULLUP);
|
||||||
@@ -87,6 +100,18 @@ void setup()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleButtonInput(ButtonInfo *but){
|
||||||
|
but->current = digitalRead(but->pinNumber);
|
||||||
|
|
||||||
|
if(but->prev == 1 && but->current ==0 ){
|
||||||
|
SwitchControlLibrary().PressButton(but->buttonSymbol);
|
||||||
|
}
|
||||||
|
else if(but->prev == 0 && but->current ==1 ) {
|
||||||
|
SwitchControlLibrary().ReleaseButton(but->buttonSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
but->prev = but->current;
|
||||||
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
@@ -101,7 +126,11 @@ void loop()
|
|||||||
prevVal = val;
|
prevVal = val;
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0; i<ButtonInfoTableSize; i++){
|
||||||
|
handleButtonInput(&(buttonInfoTable[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bButton.current = digitalRead(bButton.pinNumber);
|
bButton.current = digitalRead(bButton.pinNumber);
|
||||||
|
|
||||||
if(bButton.prev == 1 && bButton.current ==0 ){
|
if(bButton.prev == 1 && bButton.current ==0 ){
|
||||||
@@ -125,6 +154,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
plusButton.prev = plusButton.current;
|
plusButton.prev = plusButton.current;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
for (int i=0; i<4; i++){
|
for (int i=0; i<4; i++){
|
||||||
|
|||||||
Reference in New Issue
Block a user