modifyed LED Multiplex Code.

This commit is contained in:
Alexander Richter 2023-09-17 14:24:22 +02:00
parent 142366491d
commit 2eaa6a2525

View File

@ -263,13 +263,12 @@ So you could attach a QWERT* Keyboard to the arduino and you will be able to wri
*/ */
#define KEYPAD #define KEYPAD
#ifdef KEYPAD #ifdef KEYPAD
const int numRows = 3; // Define the number of rows in the matrix const int numRows = 8; // Define the number of rows in the matrix
const int numCols = 3; // Define the number of columns in the matrix const int numCols = 8; // Define the number of columns in the matrix
// Define the pins connected to the rows and columns of the matrix // Define the pins connected to the rows and columns of the matrix
const int rowPins[numRows] = {5,6,7}; //Iputs const int rowPins[numRows] = {2,3,4,5,6,7,8,9}; //Iputs
const int colPins[numCols] = {8, 9, 10}; //"Output 8-14" const int colPins[numCols] = {40,41,42,43,44,45,46,47}; //"Output 8-14"
int keys[numRows][numCols] = {0}; int keys[numRows][numCols] = {0};
int lastKey= -1; int lastKey= -1;
#endif #endif
@ -281,16 +280,16 @@ int lastKey= -1;
#ifdef MULTIPLEXLEDS #ifdef MULTIPLEXLEDS
const int numVccPins = 3; // Number of rows in the matrix const int numVccPins = 8; // Number of rows in the matrix
const int numGndPins = 3; // Number of columns in the matrix const int numGndPins = 8; // Number of columns in the matrix
const int LedVccPins[] = {2,3,4}; // Arduino pins connected to rows const int LedVccPins[] = {30,31,32,33,34,35,36,37}; // Arduino pins connected to rows
const int LedGndPins[] = {8,9,10}; // Arduino pins connected to columns const int LedGndPins[] = {40,41,42,43,44,45,46,47}; // Arduino pins connected to columns
// Define the LED matrix // Define the LED matrix
int ledStates[numVccPins*numGndPins] = {0}; int ledStates[numVccPins*numGndPins] = {0};
unsigned long previousMillis = 0; unsigned long previousMillis = 0;
const unsigned long interval = 1; // Time (in milliseconds) per LED display const unsigned long interval = 0; // Time (in milliseconds) per LED display
int currentLED = 0; int currentLED = 0;
#endif #endif
@ -495,7 +494,8 @@ void loop() {
readJoySticks(); //read Encoders & send data readJoySticks(); //read Encoders & send data
#endif #endif
#ifdef MULTIPLEXLEDS #ifdef MULTIPLEXLEDS
multiplexLeds(); //for(int i=0;i<20;i++){
multiplexLeds();//}
#endif #endif
} }
@ -919,36 +919,36 @@ void readKeypad(){
void multiplexLeds() { void multiplexLeds() {
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
//init Multiplex //init Multiplex
if(ledStates[currentLED]==1){//turn active LEDs on. #ifdef KEYPAD //if Keyboard is presend disable Pullup Resistors to not mess with LEDs while a Button is pressed.
#ifdef KEYPAD //if Keyboard is presend disable Pullup Resistors to not mess with LEDs while a Button is pressed. for (int row = 0; row < numRows; row++) {
for (int row = 0; row < numRows; row++) { pinMode(rowPins[row], OUTPUT);
pinMode(rowPins[row], OUTPUT); digitalWrite(rowPins[row], LOW);
digitalWrite(rowPins[row], LOW); }
} #endif
#endif
for (int i = 0; i < numVccPins; i++) { for (int i = 0; i < numVccPins; i++) {
pinMode(LedVccPins[i], OUTPUT); pinMode(LedVccPins[i], OUTPUT);
digitalWrite(LedVccPins[i], LOW); // Set to LOW to disable all Vcc Pins digitalWrite(LedVccPins[i], LOW); // Set to LOW to disable all Vcc Pins
} }
for (int i = 0; i < numGndPins; i++) { for (int i = 0; i < numGndPins; i++) {
pinMode(LedGndPins[i], OUTPUT); pinMode(LedGndPins[i], OUTPUT);
digitalWrite(LedGndPins[i], HIGH); // Set to HIGH to disable all GND Pins digitalWrite(LedGndPins[i], HIGH); // Set to HIGH to disable all GND Pins
} }
digitalWrite(LedVccPins[currentLED%numVccPins],HIGH); for(currentLED = 0; currentLED < numVccPins*numGndPins ;currentLED ++){
digitalWrite(LedGndPins[currentLED/numVccPins],LOW); if(ledStates[currentLED] == 1){
digitalWrite(LedVccPins[currentLED%numVccPins],HIGH);
if (currentMillis - previousMillis >= interval) { // Check if it's time to update the LED matrix digitalWrite(LedGndPins[currentLED/numVccPins],LOW);
previousMillis = currentMillis; // Save the last update time
currentLED++;
} }
} }
/*
}
if(ledStates[currentLED]==0){//If currentLED is Off, manage next one. if(ledStates[currentLED]==0){//If currentLED is Off, manage next one.
currentLED++; currentLED++;
} }
if(currentLED >= numVccPins*numGndPins){ if(currentLED >= numVccPins*numGndPins){
currentLED= 0; currentLED= 0;
} }
*/
} }
#endif #endif