Seven segments LED display, Arduino Uno or Nano egg timer. Seconds displayed, minutes are set by buttons. Also buttons for start and stop, pressing together MIN and MINx10 resets the display. Alarm at the end of count down switches on a 5VDC buzzer or a LED.
The code multiplexes the 4 digits at frequency of 120Hz. LEDs are common cathode.
The code multiplexes the 4 digits at frequency of 120Hz. LEDs are common cathode.
B4X:
Sub Process_Globals
Private s(7) As Pin
Private D8, D9, D10, D11, out12 As Pin
Private minA0, minA1, stop, start As Pin
Private cc1, cc2, cc3, cc4 As Byte
Private run=False As Boolean
Private seg() As Byte = Array As Byte(0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F)
End Sub
Private Sub AppStart
For i=0 To 6 '7 segments output pins
s(i).Initialize(i, s(i).MODE_OUTPUT)
Next
D8.Initialize(8, D8.MODE_OUTPUT) '4 digits outputs
D9.Initialize(9, D9.MODE_OUTPUT)
D10.Initialize(10, D10.MODE_OUTPUT)
D11.Initialize(11, D11.MODE_OUTPUT)
out12.Initialize(12, out12.MODE_OUTPUT) 'alarm
minA0.Initialize(minA0.A0, minA0.MODE_INPUT_PULLUP) 'minutes
minA1.Initialize(minA1.A1, minA1.MODE_INPUT_PULLUP) 'minutes x 10
stop.Initialize(stop.A2, stop.MODE_INPUT_PULLUP)
start.Initialize(stop.A3, start.MODE_INPUT_PULLUP)
set
End Sub
Sub set
Do While True
If minA0.DigitalRead=False And minA1.DigitalRead=True Then
cc3=cc3+1
If cc3>9 Then cc3=0
mux(63)
End If
If minA1.DigitalRead=False And minA0.DigitalRead=True Then
cc4=cc4+1
If cc4>9 Then cc4=0
mux(63)
End If
If minA1.DigitalRead=False And minA0.DigitalRead=False Then 'reset
cc1=0
cc2=0
cc3=0
cc4=0
End If
If start.DigitalRead=False Then
If cc3>0 Or cc4>0 Or cc3>0 Or cc4>0 Then run=True
End If
mux(10)
Do While run 'clock
If cc1=0 And cc2=0 And cc3=0 And cc4=0 Then
run=False
alarm
Else
cc1=cc1-1
End If
If cc1=255 Then
cc1=9
cc2=cc2-1
If cc2=255 Then
cc2=5
cc3=cc3-1
If cc3=255 Then
cc3=9
cc4=cc4-1
End If
End If
End If
mux(112)
Loop
Loop
End Sub
Sub alarm
Do While True
out12.DigitalWrite(True)
D8.DigitalWrite(False)
D9.DigitalWrite(False)
D10.DigitalWrite(False)
D11.DigitalWrite(False)
Delay(500)
out12.DigitalWrite(False)
mux(63)
If stop.DigitalRead=False Then set
Loop
End Sub
Sub mux(count As Byte)
For i=0 To count
D8.DigitalWrite(True)
D9.DigitalWrite(False)
D10.DigitalWrite(False)
D11.DigitalWrite(False)
seg_sel(seg(cc1))
Delay(2)
D8.DigitalWrite(False)
D9.DigitalWrite(True)
D10.DigitalWrite(False)
D11.DigitalWrite(False)
seg_sel(seg(cc2))
Delay(2)
D8.DigitalWrite(False)
D9.DigitalWrite(False)
D10.DigitalWrite(True)
D11.DigitalWrite(False)
seg_sel(seg(cc3))
Delay(2)
D8.DigitalWrite(False)
D9.DigitalWrite(False)
D10.DigitalWrite(False)
D11.DigitalWrite(True)
seg_sel(seg(cc4))
Delay(2)
If stop.DigitalRead=False Then run=False
Next
End Sub
Sub seg_sel(sn As Byte)
For i=0 To 6
If (sn Mod 2)=1 Then s(i).DigitalWrite(True) Else s(i).DigitalWrite(False)
sn=sn/2
Next
End Sub
Attachments
Last edited: