[syntax=c]
char hexaKeys[ROWS][COLS] = {
{'D','#','0','*'},
{'C','9','8','7'},
{'B','6','5','4'},
{'A','3','2','1'}
};
//Order of dtmf are : 0123456789 * #
const int DTMF_freq1[] = { 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477,1209 ,1477 };
const int DTMF_freq2[] = { 941, 697, 697, 697, 770, 770, 770, 852, 852, 852, 941 ,941 };
// here you need to put the frequency generation values for your controller in above array definition for example OCR1AH=0x2c; OCR1AL=0xd4;
void playDTMF(uint8_t number, long duration)
{
freq1.play(DTMF_freq1[number], duration);
freq2.play(DTMF_freq2[number], duration);
}
char customKey = customKeypad.getKey();
if (customKey){
switch (customKey) {
case '0':
playDTMF(0, 2ms);
break;
case '1':
playDTMF(1, 2ms);
break;
case '2':
playDTMF(2, 2ms);
break;
case '3':
playDTMF(3, 2ms);
break;
case '4':
playDTMF(4, 2ms);
break;
case '5':
playDTMF(5, 2ms);
break;
case '6':
playDTMF(6, 2ms);
break;
case '7':
playDTMF(7, 2ms);
break;
case '8':
playDTMF(8, 2ms);
break;
case '9':
playDTMF(9, 2ms);
break;
case '*':
playDTMF(10, 2ms);
break;
case '#':
playDTMF(11,2ms);
break;
default: //just in case the character read has no value at all
delay(1);
}
[/syntax]