Pages: [1]   Go Down
Author Topic: Rogue tone library, mega 2560 r3 and millis() simple problem  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm finally managing to isolate what has been messing with me with a project and it's been driving me nuts chasing it.

Anyway, using the tone library and enabling any more than two tones (on a Mega 2560 with 6 timers), causes it to not work. I've looked at the cpp, read up on timer pins and conflicts and have tried a load of variations, but it comes down to this:

Put an indicator LED in pin 40 with the - leg tied to ground thru a 1k resistor, and toggle on 

Tone tone3;
Tone tone4;

Presto! no longer works.

smiley-sad

Anybody have any ideas?


Code:
#include <Tone.h>
int blinker = 40;
unsigned long lastTime;
int blinkerState = LOW;
int wait = 200;
Tone tone1;
Tone tone2;
//Tone tone3;
//Tone tone4;
void setup()
{
  pinMode(blinker, OUTPUT);
  tone1.begin(7);
  tone2.begin(6);
//  tone3.begin(5);
//  tone4.begin(4);
}
//__________________________________________________________LOOP 
void loop()
{
  unsigned long currentMillis=millis();
  if ((currentMillis - lastTime) >=  wait)
  {
    lastTime=currentMillis;
    {
      if (blinkerState == LOW)
      {
        blinkerState = HIGH;
      }
      else
      {
        blinkerState = LOW;

      }
      digitalWrite(blinker, blinkerState);
   }
  }
}
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyway, using the tone library...

Got a link to that "tone library"?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

here it is, I think the problem may be in the .cpp, and not identifying the mega 2560,
changing this:

#if defined(__AVR_ATmega1280__)

to this:

#if defined(__AVR_ATmega1280__)||(__AVR_ATmega2560__)

might have fixed it, I'll test it this afternoon.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Thank you for the follow-up.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe that did the trick, I'll be able to tell more once I get further along with the envelopes and the hardware.

I also took out all the library inclusions in the .cpp, this seems to work:

#include <arduino.h>
#include "Tone.h"
Logged

Pages: [1]   Go Up
Jump to: