Go Down

Topic: Use a different library for an existing project (Read 825 times) previous topic - next topic

mike1212

Nov 19, 2016, 08:12 pm Last Edit: Nov 19, 2016, 08:29 pm by mike1212
Hello, i am new at C and i found this tutorial on making an audio spectrum analyzer and i want to use the Adafruit 16x32 LED Panel instead of the one that they use. What changes to make to the code they made to use this board instead?
http://apcmag.com/arduino-project-audio-spectrum-analyser.htm/

i attach the new libraries and the existing project.

Thanks in advance,
Mike

PaulS

Quote
What changes to make to the code they made to use this board instead?
You need to remove all the code that deals with the existing display, and add code that deals with your display.
The art of getting good answers lies in asking good questions.

mike1212

So i replaced the old functions with the new ones and i get these errors any ideas?

C:\Users\Mike\Documents\Arduino\libraries\FHT/FHT.h:72:10: error: 'prog_int16_t' does not name a type

 PROGMEM  prog_int16_t _cas_constants[]  = {

          ^

In file included from C:\Users\Mike\Documents\Arduino\Test1\Test1.ino:5:0:

C:\Users\Mike\Documents\Arduino\libraries\FHT/FHT.h:87:12: error: 'prog_uint8_t' does not name a type

   PROGMEM  prog_uint8_t _reorder_table[]  = {

            ^

In file included from C:\Users\Mike\Documents\Arduino\Test1\Test1.ino:5:0:

C:\Users\Mike\Documents\Arduino\libraries\FHT/FHT.h:113:12: error: 'prog_uint8_t' does not name a type

   PROGMEM  prog_uint8_t _lin_table[]  = {

            ^

In file included from C:\Users\Mike\Documents\Arduino\Test1\Test1.ino:5:0:

C:\Users\Mike\Documents\Arduino\libraries\FHT/FHT.h:131:12: error: 'prog_int16_t' does not name a type

   PROGMEM  prog_int16_t _window_func[]  = {

            ^

Here's my code
Code: [Select]


#define LIN_OUT 1
#define FHT_N 128 // set to 256 point fht
#include <FHT.h> // include the library
#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <TimerOne.h>
#define CLK 8 
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

byte sample[64];
unsigned long startTime, endTime, oldTime;
int displaySize=32;



void setup() {
 
  ADCSRA = 0xe7; // set the adc to free running mode
  ADMUX = 0x45; // use adc5
  DIDR0 = 0x20; // turn off the digital input for adc5
}

void loop() {
  startTime = millis();
  sampleInput();
  sampleFix();
  drawSpectrum();
  endTime = millis();
}

void drawSpectrum () {
    matrix.fillScreen(matrix.Color333(0, 0, 0));
    for (int disX; disX < 33; disX++) {
      matrix.drawLine(disX, 16, disX, 16-sample[disX+1], matrix.Color333(7, 0, 0));
    }
  }

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
    ADMUX = 0x45; // use adc5
    byte m = ADCL; // fetch adc data
    byte j = ADCH;
    int k = (j << 8) | m; // form into an int
    k -= 0x0200; // form into a signed int
    k <<= 6; // form into a 16b signed int
    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;
    newPos = x * (fhtCount / displaySize); // single channel half-display 15-LED wide
    tempY = fht_lin_out[newPos];
    sample[x] = ((tempY/256)*16);
  } 

}



i attach a timer library

PaulS

Quote
i attach a timer library
But not the library that generates the errors...
The art of getting good answers lies in asking good questions.

mike1212

Yes, sorry. Here it is.

PaulS

That library has not been updated to reflect changes to the PROGMEM types. Time to look for a newer version of that library. Or, visit the PROGMEM page, and make the changes yourself, using supported types.
The art of getting good answers lies in asking good questions.

mike1212


mike1212

So i found an updated library and the errors were fixed except this one..

Test1:71: error: 'fht_lin_out' was not declared in this scope

     tempY = fht_lin_out[newPos];

             ^

exit status 1
'fht_lin_out' was not declared in this scope

I searched in the librarys' functions and its declared with the same name.. So what seems to be the problem?

Code: [Select]
#include <FHT.h>
#define LIN_OUT 1
#define FHT_N 128 // set to 256 point fht
#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <TimerOne.h>
#define CLK 8 
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

byte sample[64];
unsigned long startTime, endTime, oldTime;
int displaySize=32;



void setup() {
 
  ADCSRA = 0xe7; // set the adc to free running mode
  ADMUX = 0x45; // use adc5
  DIDR0 = 0x20; // turn off the digital input for adc5
}

void loop() {
  startTime = millis();
  sampleInput();
  sampleFix();
  drawSpectrum();
  endTime = millis();
}

void drawSpectrum () {
    matrix.fillScreen(matrix.Color333(0, 0, 0));
    for (int disX; disX < 33; disX++) {
      matrix.drawLine(disX, 16, disX, 16-sample[disX+1], matrix.Color333(7, 0, 0));
    }
  }

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
    ADMUX = 0x45; // use adc5
    byte m = ADCL; // fetch adc data
    byte j = ADCH;
    int k = (j << 8) | m; // form into an int
    k -= 0x0200; // form into a signed int
    k <<= 6; // form into a 16b signed int
    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;
    newPos = x * (fhtCount / displaySize); // single channel half-display 15-LED wide
    tempY = fht_lin_out[newPos];
    sample[x] = ((tempY/256)*16);
  } 

}




here is the new library.

mike1212

Hey guys.. I still can't figure this error out.. Any ideas?

Test2:53: error: 'fht_lin_out' was not declared in this scope

     tempY = fht_lin_out[newPos];

             ^

exit status 1
'fht_lin_out' was not declared in this scope


Code: [Select]
#include <FHT.h>
#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

#define LIN_OUT 1
#define FHT_N 128

#define CLK 8 
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

byte sample[64];
unsigned long startTime, endTime, oldTime;
int displaySize=32;

void setup() {
  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
}

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
    ADMUX = 0x45; // use adc5
    byte m = ADCL; // fetch adc data
    byte j = ADCH;
    int k = (j << 8) | m; // form into an int
    k -= 0x0200; // form into a signed int
    k <<= 6; // form into a 16b signed int
    fht_input[x] = k; // put real data into bins
  }
  sei(); // Enable interrupts
  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;
    newPos = x * (fhtCount / displaySize);
    tempY = fht_lin_out[newPos];
    sample[x] = ((tempY/256)*16);
  } 
}

void drawSpectrum () {
  matrix.fillScreen(matrix.Color333(0, 0, 0));
  for (int disX; disX < 33; disX++) {
    matrix.drawLine(disX, 16, disX, 16-sample[disX+1], matrix.Color333(7, 0, 0));
  }
}

void loop() {
  startTime = millis();
  sampleInput();
  sampleFix();
  drawSpectrum();
  endTime = millis();
}



Go Up