mirror of
https://github.com/Astatin3/oliver-keypad-thing.git
synced 2026-06-09 00:28:02 -06:00
Make the lights work correctly
This commit is contained in:
+81
-63
@@ -8,6 +8,9 @@ const int switchColPins[] = {40, 38, 36, 34, 32, 30, 28, 26, 24, 22}; // Switch
|
|||||||
const int LEDRowPins[] = {51, 49, 47, 45}; // LED Rows (Anodes)
|
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)
|
const int LEDColPins[] = {41, 39, 37, 35, 33, 31, 29, 27, 25, 23}; // LED Columns (Cathodes)
|
||||||
|
|
||||||
|
const int NUM_SLIDERS = 6;
|
||||||
|
const int analogInputs[NUM_SLIDERS] = {A2, A3, A4, A5, A7, A9};
|
||||||
|
|
||||||
#define ROWS 4
|
#define ROWS 4
|
||||||
#define COLS 10
|
#define COLS 10
|
||||||
int keyState[ROWS][COLS] = {0}; // Holds the state of each key
|
int keyState[ROWS][COLS] = {0}; // Holds the state of each key
|
||||||
@@ -17,15 +20,20 @@ int keyState[ROWS][COLS] = {0}; // Holds the state of each key
|
|||||||
#define PRESSED 1
|
#define PRESSED 1
|
||||||
#define HELD 2
|
#define HELD 2
|
||||||
|
|
||||||
bool litButtons[][] = {
|
bool buttonBuffer[ROWS][COLS] = {
|
||||||
{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},
|
||||||
{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}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
bool litButtons[ROWS][COLS] = {
|
||||||
|
{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() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@@ -44,79 +52,89 @@ void setup() {
|
|||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, HIGH);
|
digitalWrite(pin, HIGH);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < NUM_SLIDERS; i++) {
|
||||||
|
pinMode(analogInputs[i], INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for(int y = 0; y < litButtons.length; y++){
|
||||||
|
// for(int x = 0; x < litButtons[y].length; x++){
|
||||||
|
// litButtons
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool arrayIsFalse(bool arr[]){
|
// bool arrayIsFalse(bool arr[]){
|
||||||
for(bool b : arr){
|
// for(bool b : arr){
|
||||||
if(!b){return false;}
|
// if(!b){return false;}
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool array2dIsFalse(bool arr[][]){
|
// bool array2dIsFalse(bool arr[][]){
|
||||||
for(bool b[] : arr){
|
// for(bool b[] : arr){
|
||||||
if(!arrayIsFalse(b)){return false;}
|
// if(!arrayIsFalse(b)){return false;}
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
void updateLights(){
|
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
|
// Find next enabled light
|
||||||
while(true){
|
// while(true){
|
||||||
if(arrayIsFalse(curLitRow)){
|
for (int row = 0; row < ROWS; row++) {
|
||||||
curLitRow = (curLitRow+1) % ROWS;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(true){
|
digitalWrite(LEDRowPins[row], HIGH); // Activate row
|
||||||
if(!litButtons[curLitRow][curLitCol]){
|
for (int col = 0; col < COLS; col++) {
|
||||||
curLitCol = (curLitCol+1) % COLS;
|
if (buttonBuffer[row][col]) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
// Serial.print(row);
|
||||||
|
// Serial.print(", ");
|
||||||
|
// Serial.println(col);
|
||||||
|
|
||||||
|
digitalWrite(LEDColPins[col], LOW);
|
||||||
|
delay(1);
|
||||||
|
digitalWrite(LEDColPins[col], HIGH);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for(int col = 0; col < COLS; col++){
|
||||||
|
// digitalWrite(LEDColPins[col], HIGH);
|
||||||
|
// }
|
||||||
|
|
||||||
|
digitalWrite(LEDRowPins[row], LOW); // Deactivate row
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// for (int row = 0; row < ROWS; row++) {
|
updateLights();
|
||||||
// digitalWrite(switchRowPins[row], LOW); // Activate row
|
|
||||||
// for (int col = 0; col < COLS; col++) {
|
for (int row = 0; row < ROWS; row++) {
|
||||||
// if (digitalRead(switchColPins[col]) == LOW) {
|
digitalWrite(switchRowPins[row], LOW); // Activate row
|
||||||
// digitalWrite(LEDRowPins[row], HIGH);
|
for (int col = 0; col < COLS; col++) {
|
||||||
// digitalWrite(LEDColPins[col], LOW);
|
if (digitalRead(switchColPins[col]) == LOW) {
|
||||||
// Serial.print("Button pressed at row ");
|
// digitalWrite(LEDRowPins[row], HIGH);
|
||||||
// Serial.print(row);
|
// digitalWrite(LEDColPins[col], LOW);
|
||||||
// Serial.print(", col ");
|
|
||||||
// Serial.println(col);
|
litButtons[row][col] = true;
|
||||||
// delay(1000); // Keep the LED on for a second
|
|
||||||
// digitalWrite(LEDRowPins[row], LOW);
|
// delay(1000); // Keep the LED on for a second
|
||||||
// digitalWrite(LEDColPins[col], HIGH);
|
// digitalWrite(LEDRowPins[row], LOW);
|
||||||
// }
|
// digitalWrite(LEDColPins[col], HIGH);
|
||||||
// }
|
}
|
||||||
// digitalWrite(switchRowPins[row], HIGH); // Deactivate row
|
}
|
||||||
// }
|
digitalWrite(switchRowPins[row], HIGH); // Deactivate row
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user