@WhatYouDoing

Как вместо одной матрицы сделать 4?

Есть 4 матрицы на 7219 соединенных последовательно друг через друга, имеется код спектр(анализатор) аудио,на вход подаю сигнал,работает только одна матрица,как сделать вывод больших количеств полос эквалайзера но на все матрицы?
#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;
}
  • Вопрос задан
  • 221 просмотр
Пригласить эксперта
Ответы на вопрос 1
a_volkov1987
@a_volkov1987
Инженер-схемотехник
Ну как минимум вам надо изменить в константах количество столбцов в матрице. Сейчас их у вас 8, а должно быть 32. У вас же 4 матрицы 8*8 использовано. Ну а дальше смотрите, чтобы функция БПФ вам отдавала нужный размер массива со значениями уровней сигнала.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы