Go Down

Topic: Arduino possibly failing to honor if/else logic (Read 605 times) previous topic - next topic


Dec 15, 2012, 01:35 am Last Edit: Dec 15, 2012, 01:38 am by qantravon Reason: 1
Using a Freeduino duemilanove analog, with Arduino 1.0.2 IDE, Adafruit WaveHC library and FFT library found here: http://neuroelec.com/2011/03/fft-library-for-arduino/

I am building a replica Ghostbusters Proton Pack with lights and sound. I would like to expand its functionality to be able to use ambient sound as a source for a visualizer effect on the various lights.

However, I've run into an unusual problem.

Here is my loop():
Code: [Select]

void loop()

equalizerMode is a boolean that will be true when the switch to enable this visualizer mode is "on." As I haven't wired up that switch yet, I am not actually checking and thus equalizerMode is always false, meaning what should happen is the first part of that if statement should be all that ever happens. As it is posted above, it works fine. However, if I un-comment the call to calcViz() (which will take input from the microphone, run a fast fourier transform (using the FFT library, and store the result to a global byte that will be used to determine how to light the lights) nothing works. The sounds don't play and the lights freeze.

Correct me if I'm wrong, but even though the input to calcViz() is just electronic noise, that part of the program never gets touched, since equalizerMode is always false. So, what could be causing this?

I can post the entire sketch, but it's fairly large, and I'm not sure if it's relevant, but if anyone wants to see it, I'll post it.

Side Note: The lights are controlled using shift registers. I can't use Serial output to try and debug, because for some reason, even enabling the Serial output (with a Serial.begin() call) causes the light patterns to lock up. Help with this would also be appreciated, although I don't actually need to read from Serial, so it's not a big deal for me if that doesn't get fixed.

Edit: cyclotron(), powerCell(), doHighFreq(), and doLowFreq() all simply take a global byte (for the first two, it's simply a counter, the second two use the result of calcViz()), and apply that to a preset byte array to choose what byte patterns to send to the shift registers, and then send it.

Nick Gammon

There's nothing wrong with if/else, or nothing would work.

I strongly suspect your FFT calculation, possibly buffer overrun, as that is what is causing it to fail.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


I know, that's why I'm so confused. If equalizerMode is always false, then calcViz() should never run, correct? and the method is sitting in the code, so it should get compiled, unless the compiler sees that it's never called and doesn't bother. But, if the code is never called, is it possible for it to cause an overrun, or do anything else that could cause it to fail?

Nick Gammon

Oh, I see. If the code isn't called it may not even be included in the object file. See if the generated file size goes up markedly if you uncomment the line. One function call would only be about 3 bytes.

Say that the function has a lot of variables, and because of that it exceeds available RAM. Merely including the function could cause it to crash.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


OK, I think you were right. That one call increased the sketch size by almost 1 kB. I looked into the FFT library, there's a define that sets how many "pools" it breaks the source into. I cut that in half, and it seems to have fixed the problem. Thanks!

James C4S

Freeduino duemilanove analog,

I have never heard of such a thing.  I suspect you just put random words together and didn't bother to post your entire code.  Let's see the next immediate post.  Oh.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131