W
W
WhatYouDoing2016-11-16 21:03:14
Arduino
WhatYouDoing, 2016-11-16 21:03:14

How to make 4 instead of one matrix?

There are 4 matrices for 7219 connected in series through each other, there is an audio spectrum (analyzer) code, I send a signal to the input, only one matrix works, how to output large numbers of equalizer bands but to all matrices?

#define LOG_OUT 1 // Turns on log function resources
#define OCTAVE 1 // Turns on octave function resources
#define FHT_N 256 // bins = [0, 1, 2:4, 5:8, 9:16, 17:32, 33:64, 65:128]

#include <LedControl.h>
#include <FHT.h>

#define DIN 12 // The arduino Digital pin that provides the data for the LED matrix
#define CS 11 // The digital pin that provides the chip select input for the LED matrix
#define CLK 10 // The digital pin that provides the clock input for the LED matrix
#define ROWS 8 // Number of rows of the LED matrix, left as a parameter in case more matrices are added
#define COLUMNS 8// Number of columns of the LED matrix, left as a parameter in case more matrices are added
int maxMag;
int ledArr[8];
int rowArr[8];



LedControl lc = LedControl(DIN, CLK, CS, 4); // Initialize the LED control

void setup() {
  maxMag = -1023;
  
  lc.shutdown(0, false);      
  lc.setIntensity(0, 1);     
  lc.clearDisplay(0);      
  
  lc.shutdown(1, false);     
  lc.setIntensity(1, 1);     
  lc.clearDisplay(1); 
  
  lc.shutdown(2, false);     
  lc.setIntensity(2, 1);     
  lc.clearDisplay(2); 
  
  lc.shutdown(3, false);     
  lc.setIntensity(3, 1);     
  lc.clearDisplay(3); 

}

void loop() {
  sampleInput();
  populateLedMatrix();
  drawLed();
}

void sampleInput() {
  memset(fht_input, 0, sizeof(fht_input));
  for (int i = 0; i < FHT_N; i++) { 
    fht_input[i] = analogRead( A0 ); 
  }
  fht_window(); // window the data for better frequency response
  fht_reorder(); // reorder the data before doing the fht
  fht_run(); // process the data in the fht
  fht_mag_octave(); // take the output of the fht
}

void populateLedMatrix() {
  memset(rowArr, 0, sizeof(rowArr));  // Zero-out the row array
  maxMag--; //This is here to continue updating the maximum magnitude
  int colIndex = COLUMNS - 1;
  for (int i = 0; i < COLUMNS; i++) {
    ledArr[i] = calcColumnVal(fht_oct_out[colIndex]);
    for (int j = 0; j < ROWS; j++) {
      if (i == 0) {
        rowArr[j] = bitRead(ledArr[i], j);
      }
      else {
        rowArr[j] = rowArr[j] + pwer(bitRead(ledArr[i], j) * 2, i);
      }
    }
    colIndex--; // This ordering is a correction for the orientation of the matrix
  }
}

void drawLed() {
  int rowIndex = ROWS - 1;
  for (int i = 0; i < ROWS; i++) {
    lc.setRow(3, rowIndex, rowArr[i]);
    rowIndex--;
  }
 
  
}

int calcColumnVal(int dB) {
  if (dB > maxMag) {
    maxMag = dB; //dynamically size the array for the input
  }
  int val = (dB * (ROWS - 1) / maxMag);
  val = pwer(2, val) - 1;
  return val;
}

int pwer(int base, int power) {
  int val = 1;
  if (power == 0) {
    return val;
  }
  while (power > 0) {
    val = val * base;
    power--;
  }
  return val;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Volkov, 2016-11-17
@a_volkov1987

Well, at least you need to change the number of columns in the matrix in the constants. Now you have 8 of them, but there should be 32. You have 4 8 * 8 matrices used. Well, then look for the FFT function to give you the desired array size with the values ​​of the signal levels.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question