Hi "Grumpy_Mike"
I'm fine on memory side I believe, I reduced memory footprint to a min (40 LEDS FHT size 32) for testing and the error is at compile time anyway, not at runtime.
here is what a failing example of the code looks like
#define LOG_OUT 1 // use the log output function
#define FHT_N 32 // set to 32 point fht
#include <FHT.h> // include the library
#include <FastLED.h>
#define DATA_PIN 51
#define CLK_PIN 52
#define LED_TYPE APA102
#define COLOR_ORDER BGR
#define NUM_LEDS 40
CRGB leds[NUM_LEDS];
#define BRIGHTNESSMAX 16
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// all red
fill_solid( leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(1000); // wait a bit (debug)
ADCSRA = 0xe7; // set the adc to free running mode, scaler 7 --> 128
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
cli(); // globally disable interrupts — UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save FHT_N samples. the loop is faster than adc gets ready so max speed
while (!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
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[i] = k; // put real data into bins
}
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_log(); // take the output of the fht
sei();
for (int i = 0; i < FHT_N / 2; i++) {
/* compiling with those 2 lines works fine and code executes OK */
if ((2 * i) < NUM_LEDS) leds[2 * i].setRGB( fht_log_out[i], 0, 0);
if ((2 * i) + 1 < NUM_LEDS) leds[(2 * i) + 1].setRGB( fht_log_out[i], 0, 0);
/* commenting out the 2 previous lines and uncommenting the 2 below = compiling error APA102_TEST_FHT:61: error: r29 cannot be used in asm here*/
// if ((2 * i) < NUM_LEDS) leds[2 * i] = CHSV( fht_log_out[i], 255, 255);
// if ((2 * i) + 1 < NUM_LEDS) leds[(2 * i) + 1] = CHSV( fht_log_out[i], 255, 255);
}
FastLED.show();
}
I've an Arduino Mega 2560 with microphone input on analog 0 and an APA102 LED strip connected to pin 51 for data and pin 52 for the clock.
when you compile the code as provided above, all runs fine. I get 32 LEDS blinking with various shades of Red depending on sound input which is not really visual but works.
if you comment out the lines where I used the setRGB call and use instead the ones where I use the CHSV call then I can't compile and get
*/path/on/my/computer/*APA102_TEST_FHT.ino: In function 'void loop()':
APA102_TEST_FHT:62: error: r28 cannot be used in asm here
}
^
APA102_TEST_FHT:62: error: r29 cannot be used in asm here
APA102_TEST_FHT:62: error: r28 cannot be used in asm here
APA102_TEST_FHT:62: error: r29 cannot be used in asm here
exit status 1
r28 cannot be used in asm here
the compiler points at the closing bracket of the loop()
I'd be curious if you can compile the same code and see if you get the compile error. No need to have the same APA LEDS equipment as the error happens at compile time.
Source of libraries: