This is an example of DTMF generation emulating a phone keyboard layout on the HTML page.
It rely on the command PIN.TONE for the generation of the 2 tones.
A table is defined in the code with the row and column frequencies.
2 pins are defined as output and must be put in parallel through 2 resistances (1 - 10 Kohm).
The duration of the tones is defined in the variable "duration" at 250msec.
The output pins are defined as D7 (GPIO13) and D8 (GPIO15)
CODE: dtmf1.bas
' DTMF test program - cicciocb 2019
' call the sub DTMF with the symbol in string format
' use the new variable HtmlEventButton$
'define the NODEMCU pin numbering
D0=16:D1=5:D2=4:D3=0:D4=2:D5=14:D6=12:D7=13:D8=15:D9=3:D10=1
duration = 250 ' duration of the tone in msec
pin_T1 = D7 'pin output tone 1
pin_T2 = D8 'pin output tone 2
'frequencies
dim rows(4) = 697, 770, 852, 941
dim cols(4) = 1209, 1336, 1477, 1633
dim SYMB$(16) = "1", "2", "3", "A", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"
cls
a$ = ""
a$ = a$ + "<table>"
a$ = a$ + "<tr>"
a$ = a$ + "<td>" + button$("1", butpress) + "</td><td>" + button$("2", butpress) + "</td>"
a$ = a$ + "<td>" + button$("3", butpress) + "</td><td>" + button$("A", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("4", butpress) + "</td><td>" + button$("5", butpress) + "</td>"
a$ = a$ + "<td>" + button$("6", butpress) + "</td><td>" + button$("B", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("7", butpress) + "</td><td>" + button$("8", butpress) + "</td>"
a$ = a$ + "<td>" + button$("9", butpress) + "</td><td>" + button$("C", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("*", butpress) + "</td><td>" + button$("0", butpress) + "</td>"
a$ = a$ + "<td>" + button$("#", butpress) + "</td><td>" + button$("D", butpress) + "</td>"
a$ = a$ + "</tr>"
a$ = a$ + "</table>"
html a$
wait
butpress:
print "butpress", HtmlEventButton$
DTMF HtmlEventButton$
return
sub DTMF(sim$)
local z
for z = 0 to 15
if (SYMB$(z) = ucase$(sim$)) then
pin.tone pin_T1, cols(z and 3), duration
pin.tone pin_T2, rows(z >> 2), duration
exit for
end if
next z
end sub
' call the sub DTMF with the symbol in string format
' use the new variable HtmlEventButton$
'define the NODEMCU pin numbering
D0=16:D1=5:D2=4:D3=0:D4=2:D5=14:D6=12:D7=13:D8=15:D9=3:D10=1
duration = 250 ' duration of the tone in msec
pin_T1 = D7 'pin output tone 1
pin_T2 = D8 'pin output tone 2
'frequencies
dim rows(4) = 697, 770, 852, 941
dim cols(4) = 1209, 1336, 1477, 1633
dim SYMB$(16) = "1", "2", "3", "A", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"
cls
a$ = ""
a$ = a$ + "<table>"
a$ = a$ + "<tr>"
a$ = a$ + "<td>" + button$("1", butpress) + "</td><td>" + button$("2", butpress) + "</td>"
a$ = a$ + "<td>" + button$("3", butpress) + "</td><td>" + button$("A", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("4", butpress) + "</td><td>" + button$("5", butpress) + "</td>"
a$ = a$ + "<td>" + button$("6", butpress) + "</td><td>" + button$("B", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("7", butpress) + "</td><td>" + button$("8", butpress) + "</td>"
a$ = a$ + "<td>" + button$("9", butpress) + "</td><td>" + button$("C", butpress) + "</td>"
a$ = a$ + "</tr><tr>"
a$ = a$ + "<td>" + button$("*", butpress) + "</td><td>" + button$("0", butpress) + "</td>"
a$ = a$ + "<td>" + button$("#", butpress) + "</td><td>" + button$("D", butpress) + "</td>"
a$ = a$ + "</tr>"
a$ = a$ + "</table>"
html a$
wait
butpress:
print "butpress", HtmlEventButton$
DTMF HtmlEventButton$
return
sub DTMF(sim$)
local z
for z = 0 to 15
if (SYMB$(z) = ucase$(sim$)) then
pin.tone pin_T1, cols(z and 3), duration
pin.tone pin_T2, rows(z >> 2), duration
exit for
end if
next z
end sub