audio spectrum analyzer Dmd p10 problem

Hello everyone
I try to write an improved audio spectrum analyzer.
In order to display. 32x16. But it does not work. It runs at 16x8. Works by winamp music USB Serial
Help me with.

code

#include <SPI.h>        
#include <DMD.h>
//#include <DMD2.h>        
#include <TimerOne.h>   
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
#define BRIGHTNESS 50
byte count=0;
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
//SoftDMD dmd(1,1);  // DMD controls the entire display

int peak_hold_time = 1;  // how long before peak decays
int peaksize; // how many individual peak bands we have (dep. binsperband)
int array[16] =    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int arraytemp[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int i, j, k, r;

void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

byte serial_getch() {
  while (Serial.available() == 0);
  return Serial.read();
}

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

void setup()
{  
   // Setup the ADC
  pinMode(A0, INPUT);
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library
  // Set prescaler 
  // ADCSRA |= PS_64; // 64 prescaler (250 kHz assuming a 16MHz clock)
  // ADCSRA |= PS_32; // 32 prescaler (500 kHz assuming a 16MHz clock)
  ADCSRA |= PS_16;    // 16 prescaler (1 MHz assuming a 16MHz clock)

  Serial.begin(19200);
  Timer1.initialize(5100); 
  Timer1.pwm(PIN_DMD_nOE, 5); // to setup PWM and the starting brightness PIN_DMD_nOE, 5         
  Timer1.attachInterrupt( ScanDMD );   
  dmd.clearScreen( true );
  //Strip.setBrightness(BRIGHTNESS);
  //dmd.setBrightness(20);
   
}

void loop()
{ 
  //dmd.drawBox(  0,  0, (32*DISPLAYS_ACROSS)-1, (16*DISPLAYS_DOWN)-1, GRAPHICS_NORMAL );  
  //dmd.setbrightness(50);
    byte rxbyte = serial_getch();
  if (rxbyte == 'j')
  {
    byte r1 = serial_getch()-48;// valor maximo 16
    byte y1 = serial_getch()-48;// valor maximo 2 (no lo utilizo)
    byte data = serial_getch()-97;// valor maximo 8
    drawLevel(r1,data,y1);
  }
  else if (rxbyte == 'i')
  {
    byte r1 = serial_getch()-48;
    byte y1 = serial_getch()-48;
    dmd.drawChar(  r1,  y1, serial_getch(), GRAPHICS_NORMAL);
  }
  //else if (rxbyte == 'k')
  //{
  //dmd.clearScreen( true ); 
  //}  
}

void drawLevel(byte r1,byte data,byte y1){
    y1 = 16;
    r1 = r1+1;  
      for (int i=0; i<=data; i++){
      dmd.drawLine(  r1, y1-1*i, r1, y1-1*i, GRAPHICS_NORMAL);  
      }
      
      for (int i=data+1; i<=16; i++){
      dmd.drawLine(  r1, y1-1*i, r1, y1-1*i, GRAPHICS_INVERSE);
      //delay(50);
      }
     }

Thank You
pued

IMG_0316.1.jpg

You know without details of the hardware the software means nothing.

However I would expect at least to see your arrays dimensioned at 32 rather than 16.

//
//  Using:
//     * 32x16-LED DMD

#define LIN_OUT 1
#define FHT_N 128 // set to 256 point fht 128

#include <FHT.h> // include the library
#include <SPI.h>
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

//-------------------------------------------------------------------------------
// Change this to MONO to for a one-channel full-display or STEREO for two-channel
//
String displayType = "MONO";
//
// Change this to MONO to for a one-channel full-display or STEREO for two-channel
//-------------------------------------------------------------------------------

byte sampleR[64]; //64
byte sampleL[64];
unsigned long startTime, endTime, oldTime;
String displayText = "DY";
String sampleSet;
int displaySize;

void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

void setup() {

  if (displayType == "MONO") {displaySize = 32;} else {displaySize = 16;}
  
  //TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe7; // set the adc to free running mode
  ADMUX = 0x45; // use adc5
  DIDR0 = 0x20; // turn off the digital input for adc5

  Timer1.initialize( 5000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

  dmd.selectFont(Arial_Black_16); // show off who wrote the app... :p
  dmd.drawString(6,1,"DY",2,GRAPHICS_NORMAL);
  delay(3000);
  dmd.drawString(6,1,"CJ",2,GRAPHICS_NORMAL);
  delay(3000);
  dmd.selectFont(SystemFont5x7);
  dmd.drawString(2,0,"Audio",5,GRAPHICS_NORMAL);
  dmd.drawString(2,9,"Analy",5,GRAPHICS_NORMAL);
  delay(3000);

}

void loop() {

  startTime = millis();
  sampleSet = "L";
  sampleInput();
  sampleFix();
  if (displaySize == 16) {
    sampleSet = "R";
    sampleInput();
    sampleFix();
  }
  drawSpectrum();
  endTime = millis();
}

void drawSpectrum () {

  if (displaySize == 16) {
    dmd.clearScreen(true);
    for (int disX; disX < 16; disX++) {
      dmd.drawLine (disX, 16, disX, 16-sampleL[disX+1], GRAPHICS_NORMAL );
      dmd.drawLine (17+disX, 16, 17+disX, 16-sampleR[disX+1], GRAPHICS_NORMAL );
    }
  } 
  else {
    dmd.clearScreen(true);
    for (int disX; disX < 33; disX++) {
      dmd.drawLine (disX, 16, disX, 16-sampleL[disX+1], GRAPHICS_NORMAL );
    }
  }
}

void sampleInput() {
  cli();  // UDRE interrupt slows this way down on arduino1.0
  for (int x=0; x<FHT_N; x++) {
    while(!(ADCSRA & 0x10)); // wait for adc to be ready
    ADCSRA = 0xf5; // restart adc
    if (sampleSet == "L") {
      ADMUX = 0x45; // use adc5
    } else {
      ADMUX = 0x44; // use adc4
    }
    byte m = ADCL; // fetch adc data
    byte j = ADCH;
    int k = (j << 8) | m; // form into an int 8
    k -= 0x0200; // form into a signed int
    k <<= 6; // form into a 16b signed int 6
    fht_input[x] = k; // put real data into bins
  }
  sei();
  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_lin();

}

void sampleFix() {

  int newPos; 
  float fhtCount, tempY;
  for (int x=0; x < displaySize; x++) {
    fhtCount = FHT_N/2;  // 2
    newPos = x * (fhtCount / displaySize); // single channel half-display 15-LED wide
    tempY = fht_lin_out[newPos]; 
    if (sampleSet == "L") {
    sampleL[x] = ((tempY/256)*16); // single channel full 16 LED high
    } else {
    sampleR[x] = ((tempY/256)*16); // single channel full 16 LED high
    }
  }  
}

Still does not work.

#include <SPI.h>        
#include <DMD.h>        
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"   
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
//DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
DMD dmd(1, 1); // creates instance of DMD to refer to in sketch

//int peak_hold_time = 1;  // how long before peak decays
//int peaksize; // how many individual peak bands we have (dep. binsperband)
int data[32];
//int arraytemp[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int i, j, k, r;
int band;

void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

byte serial_getch() {
  while (Serial.available() == 0);
  return Serial.read();
  for( band = 0; band < 32; band++ );
}

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

void setup()
{  
   // Setup the ADC
  pinMode(A0, INPUT);
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library
  // Set prescaler 
  // ADCSRA |= PS_64; // 64 prescaler (250 kHz assuming a 16MHz clock)
  // ADCSRA |= PS_32; // 32 prescaler (500 kHz assuming a 16MHz clock)
  ADCSRA |= PS_16;    // 16 prescaler (1 MHz assuming a 16MHz clock)

  Serial.begin(19200);
  Timer1.initialize(5100); 
  data[band] = serial_getch();       
  Timer1.attachInterrupt( ScanDMD );

  //dmd.drawBox(  0,  0, (32*DISPLAYS_ACROSS)-1, (16*DISPLAYS_DOWN)-1, GRAPHICS_NORMAL );
  dmd.selectFont(Arial_Black_16);
  dmd.drawString(6,1,"CJ",2,GRAPHICS_NORMAL);
  delay(3000);
  dmd.selectFont(SystemFont5x7);
  dmd.drawString(2,0,"Audio",5,GRAPHICS_NORMAL);
  dmd.drawString(2,9,"Analy",5,GRAPHICS_NORMAL);
  delay(3000);
  dmd.clearScreen( true );
  //analogWrite(PIN_DMD_nOE, 5);
}

void loop()
  { 
  int xpos;
    
  byte serial_getch();
   dmd.clearScreen( true );
   for( band = 0; band < 32; band++ )
 {
 xpos = (band*1);
 if (data[band]>=962) { dmd.drawLine( xpos, 15, xpos, 0, GRAPHICS_NORMAL ); } else
 if (data[band]>=930) { dmd.drawLine( xpos, 15, xpos, 1, GRAPHICS_NORMAL ); } else
 if (data[band]>=898) { dmd.drawLine( xpos, 15, xpos, 2, GRAPHICS_NORMAL ); } else
 if (data[band]>=866) { dmd.drawLine( xpos, 15, xpos, 3, GRAPHICS_NORMAL ); } else
 if (data[band]>=834) { dmd.drawLine( xpos, 15, xpos, 4, GRAPHICS_NORMAL ); } else
 if (data[band]>=802) { dmd.drawLine( xpos, 15, xpos, 5, GRAPHICS_NORMAL ); } else
 if (data[band]>=770) { dmd.drawLine( xpos, 15, xpos, 7, GRAPHICS_NORMAL ); } else
 if (data[band]>=738) { dmd.drawLine( xpos, 15, xpos, 8, GRAPHICS_NORMAL ); } else
 if (data[band]>=706) { dmd.drawLine( xpos, 15, xpos, 9, GRAPHICS_NORMAL ); } else
 if (data[band]>=674) { dmd.drawLine( xpos, 15, xpos, 10, GRAPHICS_NORMAL ); } else
 if (data[band]>=642) { dmd.drawLine( xpos, 15, xpos, 11, GRAPHICS_NORMAL ); } else
 if (data[band]>=610) { dmd.drawLine( xpos, 15, xpos, 12, GRAPHICS_NORMAL ); } else
 if (data[band]>=578) { dmd.drawLine( xpos, 15, xpos, 13, GRAPHICS_NORMAL ); } else
 if (data[band]>=546) { dmd.drawLine( xpos, 15, xpos, 14, GRAPHICS_NORMAL ); } else
 if (data[band]>=512) { dmd.drawLine( xpos, 15, xpos, 15, GRAPHICS_NORMAL ); } else
 if (data[band]>=480) { dmd.drawLine( xpos, 15, xpos, 16, GRAPHICS_NORMAL ); } else
 if (data[band]>=448) { dmd.drawLine( xpos, 15, xpos, 17, GRAPHICS_NORMAL ); } else
 if (data[band]>=416) { dmd.drawLine( xpos, 15, xpos, 18, GRAPHICS_NORMAL ); } else
 if (data[band]>=384) { dmd.drawLine( xpos, 15, xpos, 19, GRAPHICS_NORMAL ); } else
 if (data[band]>=352) { dmd.drawLine( xpos, 15, xpos, 20, GRAPHICS_NORMAL ); } else
 if (data[band]>=320) { dmd.drawLine( xpos, 15, xpos, 21, GRAPHICS_NORMAL ); } else
 if (data[band]>=288) { dmd.drawLine( xpos, 15, xpos, 22, GRAPHICS_NORMAL ); } else
 if (data[band]>=256) { dmd.drawLine( xpos, 15, xpos, 23, GRAPHICS_NORMAL ); } else
 if (data[band]>=224) { dmd.drawLine( xpos, 15, xpos, 24, GRAPHICS_NORMAL ); } else
 if (data[band]>=192) { dmd.drawLine( xpos, 15, xpos, 25, GRAPHICS_NORMAL ); } else
 if (data[band]>=160) { dmd.drawLine( xpos, 15, xpos, 26, GRAPHICS_NORMAL ); } else
 if (data[band]>=128) { dmd.drawLine( xpos, 15, xpos, 27, GRAPHICS_NORMAL ); } else
 if (data[band]>=96) { dmd.drawLine( xpos, 15, xpos, 28, GRAPHICS_NORMAL ); } else
 if (data[band]>=64) { dmd.drawLine( xpos, 15, xpos, 29, GRAPHICS_NORMAL ); } else
 if (data[band]>=32) { dmd.drawLine( xpos, 15, xpos, 30, GRAPHICS_NORMAL ); } else
 if (data[band]>=0) { dmd.drawLine( xpos, 15, xpos, 31, GRAPHICS_NORMAL ); }
  
  }
}

Forget all the FFT stuff and just write a bit of code to light up any LED in your matrix. That is the main thing that is going wrong, you are not accessing all the LEDs.