$regfile = "attiny45.dat"
$crystal = 8000000 'Internal clock needs to be set in fuses!
'Short And Long Push - use byte as its faster to access than bit
Dim S As Byte
Dim L As Byte
Dim I As Byte
Dim A As Byte
Dim Length As Byte
'Speaker Out
Config Pinb.0 = Output
'LED / Transistor
Config Pinb.1 = Output
'Key for speed adjustment
Config Pinb.2 = Input
'Sensors
Config Pinb.3 = Output
Config Pinb.4 = Output
Const Verz = 2
Length = 100 'Initial Speed
Do
Ddrb.4 = 1 'Set to output
Portb.4 = 0 'Discharge the Sensor input (0)
Ddrb.4 = 0 'Set the Pin to INPUT
Portb.4 = 1 'pullup ON
nop 'Wait some time
nop
nop
nop
nop
nop
nop
nop
If Pinb.4 = 1 Then 'check if the PIN is at logical high level
S = 0
Else
S = 1
End If
Ddrb.4 = 1 'Set to
Portb.4 = 0 '
Ddrb.3 = 1
Portb.3 = 0
Ddrb.3 = 0
Portb.3 = 1
nop
nop
nop
nop
nop
nop
nop
nop
If Pinb.3 = 1 Then
L = 0
Else
L = 1
End If
Ddrb.3 = 1
Portb.3 = 0
If L > 0 Then Gosub Dah
If S > 0 Then Gosub Dit
' When both buttons are "pressed" dah-dit sequence is produced
Waitms 2
Loop
End
Dit:
Portb.1 = 1 'Set the LED
Gosub Sound1 'Sound procedure creates the tone and its also the delay procedure
Portb.1 = 0 'reset the LED
Gosub Nosound 'Delay without outputting the sound
If Pinb.2 = 0 Then Length = Length + 5 'If the third button (Not a touch sensor) is pushed, the speed gets slower
If Length > 200 Then Length = 0
Return
Dah:
Portb.1 = 1
Gosub Sound1 'Dah is tripple length then dit
Gosub Sound1
Gosub Sound1
Portb.1 = 0
Gosub Nosound
If Pinb.2 = 0 Then Length = Length + 5
If Length > 200 Then Length = 0
Return
Sound1:
For I = 1 To Length
Portb.0 = 1
Waitus 500
Portb.0 = 0
Waitus 700
Next
Return
'Same as above, but without setting any ports
Nosound:
For I = 1 To Length
nop
nop
Waitus 500
nop
nop
Waitus 700
Next
Return