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