Sub Process_Globals
Type State (Duration As Int, Red As Boolean, Yellow As Boolean, Green As Boolean)
Private timer1 As Timer
Private controller As GpioController
Private pinRed, pinYellow, pinGreen As GpioPinDigitalOutput
Private states As List
Private currentStateIndex As Int
End Sub
Sub AppStart (Args() As String)
controller.Initialize
pinRed.Initialize(27, False)
pinYellow.Initialize(28, False)
pinGreen.Initialize(29, False)
states.Initialize
states.Add(CreateState(4000, True, False, False)) 'only red
states.Add(CreateState(2000, True, True, False)) 'red + yellow
states.Add(CreateState(4000, False, False, True)) 'only green
states.Add(CreateState(2000, False, True, False)) 'only yellow
timer1.Initialize("timer1", 1000)
timer1.Enabled = True
currentStateIndex = -1 'it will be incremented in Timer1_Tick
Timer1_Tick 'start with the first state
StartMessageLoop
End Sub
Private Sub Timer1_Tick
currentStateIndex = (currentStateIndex + 1) mod states.Size
Dim st As State = states.Get(currentStateIndex)
pinRed.State = st.Red
pinYellow.State = st.Yellow
pinGreen.State = st.Green
timer1.Interval = st.Duration
End Sub
Private Sub CreateState(Duration As Int, Red As Boolean, Yellow As Boolean, Green As Boolean) As State
Dim st As State
st.Initialize
st.Duration = Duration
st.Red = Red
st.Yellow = Yellow
st.Green = Green
Return st
End Sub