Use of the FreqOut Command

' DTMF_1.Bas
' Illustrates various uses of the FreqOut Command.
' User is prompted to enter a digit from the keyboard.  If a valid
' TouchTone digit, 0-9, # or *, the digit is sent in TouchTone format
' using FreqOut command.  The sequence is terminated when the user
' enters "!".
' A warble is then sent using the FreqOut command to simulate ringback.
' Note that the intent of the routine was not to realize a practical 
' application, but rather to illustrate the use of GetByte and FreqOut.
' Note that the high and low frequencies associated with a TouchTone digit
' are determined using two Select Case constructs.
' Uses simply a small speaker on Pin 13 with a series blocking capacitor.
' (If you need such a speaker, we have them for $0.50).
' copyright, 
' Onya D. Barnes, Morgan State University, Baltimore, MD, Nov, '99

Const SpkrPin as Byte = 13
Const FreqRing1 as Integer = 1500
Const FreqRing2 as Integer = 2000

Sub Main()
   Dim Entry as Byte
   Dim Success as Boolean
   Dim FreqLow as Integer
   Dim FreqHigh as Integer

   Dim N as Integer	
   Dim Str as String
   Call OpenSerialPort(1, 19200)
   Call Sleep(1.0)				
      Str = "Enter Number.  Use ! to Terminate"
      Call PutStr(Str)
      Call NewLine()

      Do	' loop until "!" character	
         Do	' loop until character received
            Call GetByte(Entry, Success)
         Loop Until (Success)

         Call PutByte(Entry)	' echo the entry	   						
         If (Entry <> Asc("!")) Then
            Select Case (Entry)	'Determine Low Frequency
               Case Asc("1"), Asc("2"), Asc("3")						
               Case Asc("4"), Asc("5"), Asc("6") 		
  	       Case Asc("7"), Asc("8"), Asc("9") 		
               Case Asc("*"), Asc("0"), Asc("#")		
               Case Else
            End Select
            Select Case (Entry)		'Determine High Frequecy
               Case Asc("1"), Asc("4"), Asc("7"), Asc("*")
               Case Asc("2"), Asc("5"), Asc("8"), Asc("0")					
               Case Asc("3"), Asc("6"), Asc("9"), Asc("#")
               Case Else 
            End Select
            Call FreqOut(SpkrPin, FreqLow, FreqHigh, 300)' send digit
         End If
      Loop Until (Entry = Asc("!"))

      		'Attempt to Simulate a Phone Ringing
      Call Sleep(0.5)
      For N=1 to 3          
         Call FreqOut(SpkrPin, FreqRing1, FreqRing2, 600)
         Call FreqOut(SpkrPin, 2*FreqRing1, 2*FreqRing2, 600)
         Call FreqOut(SpkrPin, FreqRing1, FreqRing2, 600)		
         Call Sleep(0.5)

      Str=". . . .Hello"
      Call PutStr(Str)
      Call Newline()
      Call Sleep(5.00)

End Sub