' ===================================================
' This program read the pulses of a telephone dial
' The thelephone dial is connected from Signal to GND
' Signal is normally down (Up=70ms / Down=40ms)
' ===================================================

Option Speed 9
Variable String Status = "WaitingStart"
Variable Numeric Count
Variable Numeric IN
Variable Numeric StartTime

Label Decode
	IN = Slot(1)
	Select Status
		Case "WaitingStart"
			If IN > 800
				Count = 0
				Status = "WaitingDown"
			EndIf
		Case "WaitingDown"
			If IN < 200
				Count = Count + 1
				StartTime = ElapsedTime
				Status = "WaitingUp"
			EndIf
		Case "WaitingUp"
			If IN > 800
				Status = "WaitingDown"
			EndIf
			If ElapsedTime - StartTime > 0.2
				Gosub Execute
				Status = "WaitingStart"
			EndIf
	EndSelect
Goto Decode

Label Execute
	Print "Dial counts = " + Count
	Select Count
		Case 1
			
		Case 2
			
		Case 3
			
		Case 4
			
		Case 5
			
		Case 6
			
		Case 7
			
		Case 8
			
		Case 9
			
		Case 10 ' the dial 0 has 10 pulses
			Beep
	EndSelect
Return


'WATCH SewTo_Speed
'EXEC Button 5 Text Button5
