Compare commits
6 Commits
17ec220b1e
...
ee5ef7a696
| Author | SHA1 | Date | |
|---|---|---|---|
| ee5ef7a696 | |||
| ca5fd1ae18 | |||
| 03f7212661 | |||
| 6c650e0750 | |||
| 29c419e954 | |||
| 79b9e28ae5 |
@@ -16,7 +16,17 @@ struct arrow {
|
||||
int state;
|
||||
};
|
||||
|
||||
struct ButtonInfo {
|
||||
int pinNumber;
|
||||
bool prev;
|
||||
bool current;
|
||||
Button buttonSymbol;
|
||||
};
|
||||
|
||||
struct arrow arrowTable[4];
|
||||
#define ButtonInfoTableSize 9
|
||||
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
|
||||
|
||||
|
||||
void perms() {
|
||||
if(val == 0){
|
||||
@@ -29,30 +39,38 @@ void perms() {
|
||||
}
|
||||
index = (index + 1) % 40;
|
||||
}
|
||||
/*
|
||||
void button() {
|
||||
if (state == 0) {
|
||||
SwitchControlLibrary().PressButtonA();
|
||||
state = 1;
|
||||
}
|
||||
else {
|
||||
SwitchControlLibrary().ReleaseButtonA();
|
||||
state = 0;
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
table[0] = 1;
|
||||
table[tableSize/2] = 2;
|
||||
SwitchControlLibrary();
|
||||
|
||||
MsTimer2::set(1, perms);
|
||||
MsTimer2::start();
|
||||
|
||||
setupButton(&(buttonInfoTable[0]), 3, Button::B);
|
||||
setupButton(&(buttonInfoTable[1]), 4, Button::X);
|
||||
setupButton(&(buttonInfoTable[2]), 5, Button::Y);
|
||||
setupButton(&(buttonInfoTable[3]), 16, Button::L);
|
||||
setupButton(&(buttonInfoTable[4]), 10, Button::R);
|
||||
setupButton(&(buttonInfoTable[5]), 15, Button::PLUS);
|
||||
setupButton(&(buttonInfoTable[6]), 18, Button::HOME);
|
||||
setupButton(&(buttonInfoTable[7]), 19, Button::CAPTURE);
|
||||
setupButton(&(buttonInfoTable[8]), 14, Button::MINUS);
|
||||
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
|
||||
arrowTable[0].pinNumber = 10;
|
||||
arrowTable[0].pinNumber = 6;
|
||||
arrowTable[1].pinNumber = 7;
|
||||
arrowTable[2].pinNumber = 8;
|
||||
arrowTable[3].pinNumber = 9;
|
||||
@@ -62,9 +80,20 @@ void setup()
|
||||
arrowTable[i].state = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
@@ -73,11 +102,17 @@ void loop()
|
||||
SwitchControlLibrary().PressButtonA();
|
||||
index = 1;
|
||||
}
|
||||
else if(val == 1){
|
||||
else if(prevVal == 0 && val == 1){
|
||||
SwitchControlLibrary().ReleaseButtonA();
|
||||
}
|
||||
prevVal = val;
|
||||
|
||||
|
||||
for(int i=0; i<ButtonInfoTableSize; i++){
|
||||
handleButtonInput(&(buttonInfoTable[i]));
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<4; i++){
|
||||
arrowTable[i].state = digitalRead(arrowTable[i].pinNumber);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user