Go Down

Topic: EMF meter using Arduino MEGA2650 (Read 4534 times) previous topic - next topic


I would re-examine your tone code. Maybe try getting it working by itself (without LEDs, etc) then insert it back into full program.

It looks like you "borrowed" that code from the Tone Tutorial. The tutorial uses arrays to play multiple tones. You kept it as an array, but are only playing one tone. An array of one? I'd try rewriting it/redefining it without using arrays.


Code: [Select]
[quote author=jonrobertd link=topic=170092.msg1296426#msg1296426 date=1372444099]
So I have the emf meter working perfectly until I add in the tone. Once it hits the level the tone starts, it hangs, gradually lighting an LED every second beep for a few LEDs then decreases one until it hits LED 8 (the tone LED) and hangs. I modified the tone example to suit my needs in this application, but have no idea why it hangs there once it hits level 8.

int melody[] = {
  NOTE_C4 };

int noteDurations[] = {
  4 };
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;


Lose the above code. That's for playing a melody. You're setting an array of one note. Then, pausing between notes....but you're only playing one note. So....probably why it's hanging.

Replace it with something simple, like -
Code: [Select]

tone(speakerPin, 1000, 500);

Plays a tone on speakerPin of 1000 Hz for 500 ms (1/2 sec).
Then, turns off tone so won't interfere with nothing else.

And in beginning of code, maybe add an
Code: [Select]

Const int speakerPin = 8;

I'm guessing from your code that's where you have speaker hooked up.

With all those If/else statements though....it might be difficult to smoothly add in beeps & such.

Should be able to map the input of sensor to a set of values equal to the number of LEDs, assign LEDs to an array, then just call the mapped values to turn the correlating LEDs HIGH.


Yes I used the tone code, hoping it would work but I see now why it doesn't.  Thank you for all of your help and I will try what 1ChigagoDave suggested and will try tinkering some more.

Go Up