From d92b0a9e6af43a8dab4946b17f5b4caa4fbfc18b Mon Sep 17 00:00:00 2001 From: Astatin3 <77305074+Astatin3@users.noreply.github.com> Date: Tue, 7 May 2024 13:29:59 -0600 Subject: [PATCH] Initial commit --- .gitattributes | 2 + LICENSE | 21 ++++++++ README.md | 2 + keypad/keypad.ino | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 .gitattributes create mode 100644 LICENSE create mode 100644 README.md create mode 100644 keypad/keypad.ino diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6e485a0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Astatin3 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..85c8e57 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# oliver-keypad-thing + diff --git a/keypad/keypad.ino b/keypad/keypad.ino new file mode 100644 index 0000000..339d9a5 --- /dev/null +++ b/keypad/keypad.ino @@ -0,0 +1,133 @@ +#include + +// Define pin mappings for the switch matrix +const int switchRowPins[] = {50, 48, 46, 44}; // Switch Rows +const int switchColPins[] = {40, 38, 36, 34, 32, 30, 28, 26, 24, 22}; // Switch Columns + +// Define the pin arrays for the LED matrix +const int LEDRowPins[] = {51, 49, 47, 45}; // LED Rows (Anodes) +const int LEDColPins[] = {41, 39, 37, 35, 33, 31, 29, 27, 25, 23}; // LED Columns (Cathodes) + +#define ROWS 4 +#define COLS 10 +int keyState[ROWS][COLS] = {0}; // Holds the state of each key + +// State definitions for key states +#define NONE 0 +#define PRESSED 1 +#define HELD 2 + +bool litButtons[][] = { + {false, false, false, false, false, false, false, false, false, false}, + {false, false, false, false, false, false, false, false, false, false}, + {false, false, false, false, false, false, false, false, false, false}, + {false, false, false, false, false, false, false, false, false, false} +} + +int curLitRow = -1; +int curLitCol = -1; + +void setup() { + Serial.begin(9600); + for (int pin : switchRowPins) { + pinMode(pin, OUTPUT); + digitalWrite(pin, HIGH); + } + for (int pin : switchColPins) { + pinMode(pin, INPUT_PULLUP); + } + for (int pin : LEDRowPins) { + pinMode(pin, OUTPUT); + digitalWrite(pin, LOW); + } + for (int pin : LEDColPins) { + pinMode(pin, OUTPUT); + digitalWrite(pin, HIGH); + } +} + +bool arrayIsFalse(bool arr[]){ + for(bool b : arr){ + if(!b){return false;} + } + return true; +} + +bool array2dIsFalse(bool arr[][]){ + for(bool b[] : arr){ + if(!arrayIsFalse(b)){return false;} + } + return true; +} + +void updateLights(){ + + if(array2dIsFalse(litButtons)){ + curLitRow = -1; + curLitCol = -1; + return; + } + + if(curLitRow == -1){ + curLitRow = 0; + }else{ + curLitRow = (curLitRow+1) % ROWS; + } + + if(curLitCol == -1){ + curLitCol = 0; + }else{ + curLitCol = (curLitCol+1) % COLS; + } + + // Find next enabled light + while(true){ + if(arrayIsFalse(curLitRow)){ + curLitRow = (curLitRow+1) % ROWS; + continue; + } + + while(true){ + if(!litButtons[curLitRow][curLitCol]){ + curLitCol = (curLitCol+1) % COLS; + continue; + } + + break; + } + } + +} + +void loop() { + // for (int row = 0; row < ROWS; row++) { + // digitalWrite(switchRowPins[row], LOW); // Activate row + // for (int col = 0; col < COLS; col++) { + // if (digitalRead(switchColPins[col]) == LOW) { + // digitalWrite(LEDRowPins[row], HIGH); + // digitalWrite(LEDColPins[col], LOW); + // Serial.print("Button pressed at row "); + // Serial.print(row); + // Serial.print(", col "); + // Serial.println(col); + // delay(1000); // Keep the LED on for a second + // digitalWrite(LEDRowPins[row], LOW); + // digitalWrite(LEDColPins[col], HIGH); + // } + // } + // digitalWrite(switchRowPins[row], HIGH); // Deactivate row + // } +} + +// #include + + +// void setup() { +// //Test serial out +// Serial.begin(115200); +// delay(10000); +// Serial.print("Test"); +// } + +// void loop() { +// } \ No newline at end of file