#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private pin2 As Pin
Private timer1 As Timer
Private counter As UInt
Private set= False As Boolean
Private flowrate As Double
Private totalmililiter=0 As Double
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
pin2.Initialize(2,pin2.MODE_INPUT_PULLUP)
pin2.AddListener("pin2_StateChanged")
timer1.Initialize("timer1_Tick",2000)
timer1.Enabled=True
End Sub
Private Sub timer1_Tick()
'Start the math
'As per the datasheet 450 Pulse per Liter. So we can get 1000/450 or 2.25ML per Pulse.
flowrate=(counter*2.25)
flowrate=flowrate*60 'ML(MilliLitres) per minutes
'Conversion of MilliLitres to Liters
flowrate=NumberFormat((flowrate/1000),0,2)
totalmililiter=(totalmililiter+flowrate)
Log("Flowrate: ",flowrate, " Liter/Minute")
'Print the cumulative total of litres flowed since starting
Log("Total Output Liquid Quantity: ", NumberFormat(totalmililiter,0,2))
'Log("Counter is :",counter)
counter=0 'Resetting the Counter
set= False
End Sub
Private Sub pin2_StateChanged(state As Boolean)
Select state
Case True
counter=counter+1
Case False
End Select
End Sub