HI,
i've ported an sketch from an NANO to a MEGA 2560 with ethernet shield.
Everything but the tone works like charm.
When i use tone or (newtone), it plays the desired tone but also an ~1khz tone that can't be stopped anymore.
I've tried several PWM outputs to prevent timer issues without luck.
here's a bit of my code:
//#include <SD.h>
//#include <NewTone.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <RCSwitch.h>
#include "pitches.h"
//-----------------------------------------------------------------------------------------------
// Ethernet configuration
//-----------------------------------------------------------------------------------------------
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
byte ip[] = { 192,168,1, 200 }; // IP Address
EthernetServer server(80); // Server Port 80
//-----------------------------------------------------------------------------------------------
// UDP/NTP configuration
//-----------------------------------------------------------------------------------------------
unsigned int localPort = 8888; // local port to listen for UDP packets
IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server
const byte timeZoneOffset = +1; // GMT zone;
//-----------------------------------------------------------------------------------------------
// EMAIL configuration
//-----------------------------------------------------------------------------------------------
char Mailserver[] = "mail.gmx.net";
//-----------------------------------------------------------------------------------------------
// RC configuration
//-----------------------------------------------------------------------------------------------
byte RCTransmissionPin = 7; // pin attached to RC transmitter
byte RCRXinterrupt = 0; // Receiver on inerrupt 0 => that is pin #2
//-----------------------------------------------------------------------------------------------
// AUDIO configuration
//-----------------------------------------------------------------------------------------------
const byte BuzzerPin = 46; // pin for the piezzo buzzer
unsigned int pace = 1150; // music speed
//-----------------------------------------------------------------------------------------------
//--------------- NO MORE EDITING BELOW THIS LINE!!!! ------------------------------------------
//-----------------------------------------------------------------------------------------------
// --------------------------------------
// alarm state definitions
// --------------------------------------
const byte arm = 1;
const byte disarm = 2;
const byte alert = 3;
// --------------------------------------
// sensor definition
// --------------------------------------
typedef struct a_sensor{
unsigned long id; // decimal RC code
String name; // readable name
byte level; // 0=always on, 1=nightmode, 2=full armed
unsigned long lasttime;
boolean hastriggered;
byte action;
unsigned int timedelay;
a_sensor* nextsensor;
} a_sensor;
a_sensor *root; // root of the sensorlist
a_sensor *lastknown; // last triggered sensor
// --------------------------------------
unsigned long lastreceived; // holds the last received decimal code from rc sensor
unsigned long lastreceivedlength;
byte armedlevel = 0; // holds the alarm level (0= only alway on/fire/smoke,...)
byte prealarmcounter = 0;
byte prealarmid;
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
time_t prevDisplay = 0; // when the digital clock was displayed
EthernetUDP Udp; // A UDP instance to let us send and receive packets over UDP
EthernetClient client;
RCSwitch mySwitch = RCSwitch(); // RCSwitch configuration
// --------------------------------------
// Buzzer Melody definition
// --------------------------------------
const int *currentMelody;
byte *currentMelodyDurations;
byte currentMelodyPosition = 0;
byte currentMelodyLength = 0;
const int melodyBeep[] = {NOTE_C5, NOTE_C6};
byte noteDurationsBeep[] = {8, 16};
byte melodyBeepLength = 2;
const int melodyUp[] = {NOTE_C4, NOTE_D4, NOTE_G4};
byte noteDurationsUp[] = {4, 8, 16};
byte melodyUpLength = 3;
const int melodyDown[] = {NOTE_G4, NOTE_D4, NOTE_C4};
byte noteDurationsDown[] = {4, 8, 16};
byte melodyDownLength = 3;
const int melodyAlarm[] = {NOTE_C6, NOTE_G6, NOTE_C6, NOTE_G5, NOTE_C7, NOTE_C6};
byte noteDurationsAlarm[] = {16, 16, 8, 8, 4, 8};
byte melodyAlarmLength = 6;
boolean playsound = false;
boolean playloop = false;
//---------------------------------------------------------------------------------------------
// Setup
// ---------------------------------------------------------------------------------------------
void setup() {
// initialise serial port for debugging
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// initialise alert system
InitialiseSettings();
// Network initialisation
// Initialise ethernet
Ethernet.begin(mac, ip);
// start http server
server.begin();
//initialise UDP
Udp.begin(localPort);
// set the NTP service host
setSyncProvider(getNtpTime);
//sync arduino time with NTP Time
//while(timeStatus()== timeNotSet); // wait until the time is set by the sync provider
//enable transmittion of rc-commands on RCTransmissionPin
mySwitch.enableTransmit( RCTransmissionPin );
//enable reception of rc-commands on RCRXPin
mySwitch.enableReceive(RCRXinterrupt); // Receiver on inerrupt 0 => that is pin #2
tone(BuzzerPin,440,10); // HERE THE PROBLEM OCCURS
}
Thanks for any advice