Compiling error

Hello.

I’m making an DTMF encoder with an arduino uno r3, soft v1.0.3, but I’m having some problems compiling this code.

every thing I’m using, including libraries, can be found in this file:
OldPhone - My arduino code
Tone - Library
www.ruicaldas.com/downloads/OldPhone.zip

Can anyone point me in the right direction?

Thanks in advanced!

the error messages:
OldTelephone.cpp.o: In function playDTMF(unsigned char, long)': C:\Program Files (x86)\arduino-1.0.3/OldTelephone.ino:38: undefined reference to Tone::play(unsigned int, unsigned long)’
C:\Program Files (x86)\arduino-1.0.3/OldTelephone.ino:39: undefined reference to Tone::play(unsigned int, unsigned long)' OldTelephone.cpp.o: In function setup’:
C:\Program Files (x86)\arduino-1.0.3/OldTelephone.ino:31: undefined reference to Tone::begin(unsigned char)' C:\Program Files (x86)\arduino-1.0.3/OldTelephone.ino:33: undefined reference to Tone::begin(unsigned char)’

the code:

#include <Tone.h>
Tone COL;
Tone ROW;
const int DTMF_COL[] = { 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477 };
const int DTMF_ROW[] = {  941,  697,  697,  697,  770,  770,  770,  852,  852,  852 };

const int colTonepin = 6;
const int rowTonepin = 7;
const int dialingPin = 4;
const int pulsePin = 2;
const int ledPin = 13;

int buttonPushCounter = 0;
int pulseCounter = 0;
int dialingPinState = 0;
int pulsePinState = 0;
int lastdialingPinState = 1;
int lastpulsePinState = 0;
int number = 0;

void setup() {
  pinMode(colTonepin, OUTPUT);
  pinMode(rowTonepin, OUTPUT);
  pinMode(dialingPin, INPUT);
  pinMode(pulsePin, INPUT);
  pinMode(ledPin, OUTPUT);
  
  COL.begin(6);
  ROW.begin(7);

  Serial.begin(9600);
}

void playDTMF(uint8_t number, long duration) {
  COL.play(DTMF_COL[number], duration);
  ROW.play(DTMF_ROW[number], duration);
}

void loop() {
  delay(5);
  dialingPinState = digitalRead(dialingPin);
  pulsePinState = digitalRead(pulsePin);

  if (dialingPinState != lastdialingPinState) {
      if (dialingPinState == HIGH) {
        Serial.println("dialing ON");       
      }
      else {
        if (number == 0) {
          Serial.println("NO INPUT");
        }
        if (number == 1) {
          Serial.println(number);
          playDTMF(1, 500);
        }
        if (number == 2) {
          Serial.println(number);
        }
        if (number == 3) {
          Serial.println(number);
        }
        if (number == 4) {
          Serial.println(number);
        }
        if (number == 5) {
          Serial.println(number);
        }
        if (number == 6) {
          Serial.println(number);
        }
        if (number == 7) {
          Serial.println(number);
        }
        if (number == 8) {
          Serial.println(number);
        }
        if (number == 9) {
          Serial.println(number);
        }
        if (number == 10) {
          Serial.println("0");
        }
        Serial.println("dialing OFF");
        number = 0;
      }
  } 
  if (dialingPinState == HIGH) {
    if (pulsePinState != lastpulsePinState) {
          if (pulsePinState == HIGH) {
            number++;
          }
        }
  }
  // save the current state as the last state, 
  //for next time through the loop
  lastpulsePinState = pulsePinState;
  lastdialingPinState = dialingPinState;
}

Sorry! Found an error. Pin 6 and 7 in use... changed to 11 12 but the problem maintains!

  COL.begin(11);
  ROW.begin(12);

Just a note; consider using Switch instead of if if if if http://arduino.cc/en/Reference/SwitchCase switch (var) { case 1: //do something when var equals 1 break; case 2: //do something when var equals 2 break; etc...

Where did you get the Tone.h file from, I've got the same Tone.cpp, from the Arduino core library, however it doesn't match the Tone.h that you've got, they have completely different functions in them, Tone.h declares a class Tone, which you have been trying to use in your code, but the Tone.cpp files seems to contain a bunch of static functions, and doesn't even include Tone.h, as these are defined in Arduino.h.

Sorry that this doesn't really offer much of a solution, I suppose you've either got to hunt down the cpp file that goes with Tone.h, or use the functions in the arduino library: http://arduino.cc/en/Reference/Tone

Hi

You are right!

The h file and the cpp file are not made for each other.

re download them again, from the same site, and junt changed the include wires.h to arduino.h and it's working!

Sorry for any inconvenience!

btw, the thing working: www.ruicaldas.com/downloads/OldPhoneFix.zip