Pages: 1 [2]   Go Down
Author Topic: EMF meter using Arduino MEGA2650  (Read 1402 times)
0 Members and 1 Guest are viewing this topic.
Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
[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;
    delay(pauseBetweenNotes);
    noTone(8);
 
}
[/quote]

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:
tone(speakerPin, 1000, 500);
NoTone(speakerPin);

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:
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.


Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: