From a7e547d4a0e975d672e05735688990478c6e5de9 Mon Sep 17 00:00:00 2001 From: Zepheris Date: Sat, 17 Oct 2020 02:28:29 -0600 Subject: [PATCH] Completed Rotary code. --- src/main.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e566729..c03f6cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,8 +8,10 @@ //numPCFButtons is greater than 8, its expected to be using 2 PCF8572 chips (multiples of 8) const int numPCFButtons = 8; const int numRotaries = 3; -const int rotJoy[numRotaries] = { - 32,30,28 +const int rotJoy[numRotaries] [2] = { + {31,30}, + {29,28}, + {27,26} }; unsigned long btnTime[numPCFButtons] = {0}; unsigned long rotTime[numRotaries] = {0}; @@ -17,7 +19,7 @@ unsigned long btnPressedTime[numPCFButtons] = {0}; unsigned long rotPressedTime[numRotaries] = {0}; int btnState[numPCFButtons] = {0}; int rotState[numRotaries] = {0}; -const unsigned long gButtonDelta = 15; +const unsigned long gButtonDelta = 30; const unsigned long gButtonPressedDelta = 100; //Setup I/O Expander Chips @@ -108,8 +110,6 @@ void processBtn1(int i) { // btnState[i] = 0; // break; default: - //joystick.button(i).letgo <--psudo code - //Start Debug Code joy.releaseButton(i); digitalWrite(LED_BUILTIN, LOW); Serial.write("Button: "); @@ -133,27 +133,29 @@ void processRot1(int i) { Serial.println("RIGHT"); rotState[i] = 1; rotTime[i] = millis() + gButtonDelta; - joy.releaseButton(rotJoy[i]); - joy.pressButton(rotJoy[i]); - 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 + Serial.println(rotJoy[i][0]); + joy.releaseButton(rotJoy[i][0]); delay(15); + joy.pressButton(rotJoy[i][0]); + digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, HIGH); } else { Serial.println("LEFT"); rotState[i] = 1; rotTime[i] = millis() + gButtonDelta; - joy.releaseButton(rotJoy[i-1]); - joy.pressButton(rotJoy[i-1]); - 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 + Serial.println(rotJoy[i][1]); + joy.releaseButton(rotJoy[i][1]); delay(15); + joy.pressButton(rotJoy[i][1]); + digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, HIGH); } } if (rotState[i] == 1) { - if (millis() >= rotTime[1]) { + if (millis() >= rotTime[i]) { Serial.println("Encoder Off"); digitalWrite(LED_BUILTIN,LOW); - joy.releaseButton(rotJoy[i]); - joy.releaseButton(rotJoy[i-1]); + joy.releaseButton(rotJoy[i][0]); + joy.releaseButton(rotJoy[i][1]); rotState[i] = 0; } }