arduino DMD P10 audio spectrum analyzer

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
cj70
Posts: 4
Joined: Fri Mar 30, 2018 10:59 am

arduino DMD P10 audio spectrum analyzer

Post by cj70 » Fri Mar 30, 2018 11:14 am

Hello everyone
I have created a web page.
arduino does not work as expected 32x16
Guided as a guideline.

https://youtu.be/TXAy3ArZMPY
Attachments
IMG_0316.1.jpg

cj70
Posts: 4
Joined: Fri Mar 30, 2018 10:59 am

Re: arduino DMD P10 audio spectrum analyzer

Post by cj70 » Fri Mar 30, 2018 11:23 am

code use

Code: Select all

#include <SPI.h>        
#include <DMD.h>        
#include <TimerOne.h>   
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
byte count=0;
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

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();
}

void setup(void)
{
  Serial.begin(19200);
  Timer1.initialize( 3000 );           
  Timer1.attachInterrupt( ScanDMD );   
  dmd.clearScreen( true ); 
}

void loop(void)
{   
    byte rxbyte = serial_getch();
  if (rxbyte == 'j')
  {
    byte r1 = serial_getch()-48;// valor maximo 16
    byte r2 = serial_getch()-48;// valor maximo 2 (no lo utilizo)
    byte data = serial_getch()-97;// valor maximo 8
    drawLevel(r1,data);
  }
  else if (rxbyte == 'i')
  {
    byte r1 = serial_getch()-48;
    byte r2 = serial_getch()-48;
    dmd.drawChar(  r1,  r2, serial_getch(), GRAPHICS_NORMAL );
  }
  else if (rxbyte == 'k')
  {
  dmd.clearScreen( true ); 
  }  
}

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

 

cj70
Posts: 4
Joined: Fri Mar 30, 2018 10:59 am

Re: arduino DMD P10 audio spectrum analyzer

Post by cj70 » Fri Mar 30, 2018 11:25 am

Another program code.

Code: Select all

#include <SPI.h>        
#include <DMD.h>        
#include <TimerOne.h>
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
byte count=0;
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

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();
}

void setup(void)
{
  Serial.begin(19200);
  Timer1.initialize( 5000 );           
  Timer1.attachInterrupt( ScanDMD );   
  dmd.clearScreen( true ); 
}

void loop(void)
{
   byte rxbyte = serial_getch();
   if (rxbyte == 'j')
    if (Serial.read() != 0xff)  return;
 
  for (int i = 0; i != 16; array[i++] = Serial.read());
 
  for (int j = 0; j != 16; ++j) {
    const int val = array[j];
    if (val < 0 | val > 16 | val == arraytemp[j])  continue;
    arraytemp[j] = val;

    if (val < 2)  dmd.drawLine(2 * j, 0, 2 * j, 15, GRAPHICS_NORMAL);
    else          dmd.drawLine(2 * j, 15, 2 * j, 0, GRAPHICS_NORMAL);
 
    dmd.drawLine(2 * j + 1, 0, 2 * j + 1, 15, GRAPHICS_NORMAL);

    switch (val) {
    case 1:
      dmd.drawLine(2 * j, 15, 2 * j, 15, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 15, GRAPHICS_NORMAL);
      break;
    case 2:
      dmd.drawLine(2 * j, 15, 2 * j, 14, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 14, GRAPHICS_NORMAL);
      break;
    case 3:
      dmd.drawLine(2 * j, 15, 2 * j, 13, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 13, GRAPHICS_NORMAL);
      break;
    case 4:
      dmd.drawLine(2 * j, 15, 2 * j, 12, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 12, GRAPHICS_NORMAL);
      break;
    case 5:
      dmd.drawLine(2 * j, 15, 2 * j, 11, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 11, GRAPHICS_NORMAL);
      break;
    case 6:
      dmd.drawLine(2 * j, 15, 2 * j, 10, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 10, GRAPHICS_NORMAL);
      break;
    case 7:
      dmd.drawLine(2 * j, 15, 2 * j, 9, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 9, GRAPHICS_NORMAL);
      break;
    case 8:
      dmd.drawLine(2 * j, 15, 2 * j, 8, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 8, GRAPHICS_NORMAL);
      break;
    case 9:
      dmd.drawLine(2 * j, 15, 2 * j, 7, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 7, GRAPHICS_NORMAL);
      break;
    case 10:
      dmd.drawLine(2 * j, 15, 2 * j, 6, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 6, GRAPHICS_NORMAL);
      break;
    case 11:
      dmd.drawLine(2 * j, 15, 2 * j, 5, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 5, GRAPHICS_NORMAL);
      break;
    case 12:
      dmd.drawLine(2 * j, 15, 2 * j, 4, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 4, GRAPHICS_NORMAL);
      break;
    case 13:
      dmd.drawLine(2 * j, 15, 2 * j, 3, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 3, GRAPHICS_NORMAL);
      break;
    case 14:
      dmd.drawLine(2 * j, 15, 2 * j, 2, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 2, GRAPHICS_NORMAL);
      break;
    case 15:
      dmd.drawLine(2 * j, 15, 2 * j, 1, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 1, GRAPHICS_NORMAL);
      break;
    case 16:
      dmd.drawLine(2 * j, 15, 2 * j, 0, GRAPHICS_NORMAL);
      dmd.drawLine(2 * j + 1, 15, 2 * j + 1, 0, GRAPHICS_NORMAL);
    }
  }
}



 

cj70
Posts: 4
Joined: Fri Mar 30, 2018 10:59 am

Re: arduino DMD P10 audio spectrum analyzer

Post by cj70 » Wed Apr 04, 2018 12:09 am

It does not work
Please advise me

Code: Select all

#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 ); }
  
  }
}

 

Post Reply