Here is a sketch I'm playing with to generate DTMF tones.
// 2 Tones using Blink without delay JDS 25 June 2014
// Constants
//int Number[] = {2, 5, 4, 3, 8, 1, 5};
int Number[] = {4, 3, 1, 1, 0, 3, 6}; // Phone number
//DTMF frequencys
//int HTones[] = {1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477};
//int LTones[] = {941, 697, 697, 697, 770, 770, 770, 852, 852, 852};
//DTMF tones freq * 2 = Half Cycles
//int HTones[] = {2672, 2418, 2672, 2954, 2418, 2672, 2954, 2418, 2672, 2954};
//int LTones[] = {1882, 1394, 1394, 1394, 1540, 1540, 1540, 1704, 1704, 1704};
//DTMF tones microseconds = 1/(freq*2)
int HTones[] = {374, 414, 374, 339, 414, 374, 339, 414, 374, 339};
int LTones[] = {531, 717, 717, 717, 649, 649, 649, 587, 587, 587};
// Slightly lower microseconds to make up for loop overhead
//int HTones[] = {364, 404, 364, 329, 404, 364, 329, 404, 364, 329};
//int LTones[] = {521, 707, 707, 707, 639, 639, 639, 577, 577, 577};
const int HTone = 7; // Pin D7
const int LTone = 8; // Pin D8
//Variables
byte HToneState = LOW;
byte LToneState = LOW;
int i = 0;
int j = 0;
unsigned long s; // only for trouble shooting
unsigned long e; // "
long PrevMicrosHTone = 0;
long PrevMicrosLTone = 0;
long PrevMillis = 0;
long HToneInterval = 414; // 1/(1209*2)
long LToneInterval = 717; // 1/(697*2)
long ToneInterval = 150;
unsigned long CurrentMicros = micros();
unsigned long CurrentMillis = millis();
void setup() {
// put your setup code here, to run once:
pinMode(HTone, OUTPUT);
pinMode(LTone, OUTPUT);
Serial.begin(9600);
Serial.print(__FILE__ " " __DATE__ " " __TIME__);
Serial.print(" IDE "); Serial.println(ARDUINO);
}
void loop() {
if (i >6)
{i = 0; delay(4000); Serial.println();} // 4 seconds between redial
j = Number[i]; Serial.print(j); // digit to dial
//Serial.println(e - s);
i = i++;
delay(100); //Blocking delay between digits
HToneState = LOW;
LToneState = LOW;
PrevMillis = millis(); // set prev millis and micros
PrevMicrosHTone = micros();
PrevMicrosLTone = micros();
while (millis() - PrevMillis < ToneInterval) // send tones for 150ms each
{
if (micros() - PrevMicrosHTone +0 > HTones[j])// + 6 to 17 fix for loop delay
{PrevMicrosHTone = micros();
//HToneState = !HToneState;
//digitalWrite(HTone, HToneState); // High Tone
PIND = 0x80; // toggle pin D7
}
if (micros() - PrevMicrosLTone +0 > LTones[j])
{ PrevMicrosLTone = micros();
//LToneState = !LToneState;
//digitalWrite(LTone, LToneState); //Low Tone
PINB = 0x01;// toggle pin D8
}
}
}
I just need a way to make the tones into sine waves. any ideas?