Completed Rotary code.

This commit is contained in:
2020-10-17 02:28:29 -06:00
parent f60e44e79c
commit a7e547d4a0

View File

@ -8,8 +8,10 @@
//numPCFButtons is greater than 8, its expected to be using 2 PCF8572 chips (multiples of 8) //numPCFButtons is greater than 8, its expected to be using 2 PCF8572 chips (multiples of 8)
const int numPCFButtons = 8; const int numPCFButtons = 8;
const int numRotaries = 3; const int numRotaries = 3;
const int rotJoy[numRotaries] = { const int rotJoy[numRotaries] [2] = {
32,30,28 {31,30},
{29,28},
{27,26}
}; };
unsigned long btnTime[numPCFButtons] = {0}; unsigned long btnTime[numPCFButtons] = {0};
unsigned long rotTime[numRotaries] = {0}; unsigned long rotTime[numRotaries] = {0};
@ -17,7 +19,7 @@ unsigned long btnPressedTime[numPCFButtons] = {0};
unsigned long rotPressedTime[numRotaries] = {0}; unsigned long rotPressedTime[numRotaries] = {0};
int btnState[numPCFButtons] = {0}; int btnState[numPCFButtons] = {0};
int rotState[numRotaries] = {0}; int rotState[numRotaries] = {0};
const unsigned long gButtonDelta = 15; const unsigned long gButtonDelta = 30;
const unsigned long gButtonPressedDelta = 100; const unsigned long gButtonPressedDelta = 100;
//Setup I/O Expander Chips //Setup I/O Expander Chips
@ -108,8 +110,6 @@ void processBtn1(int i) {
// btnState[i] = 0; // btnState[i] = 0;
// break; // break;
default: default:
//joystick.button(i).letgo <--psudo code
//Start Debug Code
joy.releaseButton(i); joy.releaseButton(i);
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
Serial.write("Button: "); Serial.write("Button: ");
@ -133,27 +133,29 @@ void processRot1(int i) {
Serial.println("RIGHT"); Serial.println("RIGHT");
rotState[i] = 1; rotState[i] = 1;
rotTime[i] = millis() + gButtonDelta; rotTime[i] = millis() + gButtonDelta;
joy.releaseButton(rotJoy[i]); Serial.println(rotJoy[i][0]);
joy.pressButton(rotJoy[i]); joy.releaseButton(rotJoy[i][0]); delay(15);
digitalWrite(LED_BUILTIN, LOW); //This can be written for joystick.letgo. This is in case the button is still being pressed, it will let go before pressing it again joy.pressButton(rotJoy[i][0]);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
} else { } else {
Serial.println("LEFT"); Serial.println("LEFT");
rotState[i] = 1; rotState[i] = 1;
rotTime[i] = millis() + gButtonDelta; rotTime[i] = millis() + gButtonDelta;
joy.releaseButton(rotJoy[i-1]); Serial.println(rotJoy[i][1]);
joy.pressButton(rotJoy[i-1]); joy.releaseButton(rotJoy[i][1]); delay(15);
digitalWrite(LED_BUILTIN, LOW); //This can be written for joystick.letgo. This is in case the button is still being pressed, it will let go before pressing it again joy.pressButton(rotJoy[i][1]);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
} }
} }
if (rotState[i] == 1) { if (rotState[i] == 1) {
if (millis() >= rotTime[1]) { if (millis() >= rotTime[i]) {
Serial.println("Encoder Off"); Serial.println("Encoder Off");
digitalWrite(LED_BUILTIN,LOW); digitalWrite(LED_BUILTIN,LOW);
joy.releaseButton(rotJoy[i]); joy.releaseButton(rotJoy[i][0]);
joy.releaseButton(rotJoy[i-1]); joy.releaseButton(rotJoy[i][1]);
rotState[i] = 0; rotState[i] = 0;
} }
} }