Sub Process_Globals
'Define the BH1750 device. The I2C address used is 0x23 - check out with sudo i2cdetect
Private bh As BH1750
'Define the request timer and interval
Private RequestTimer As Timer
Private RequestInterval As Long = 2000
End Sub
Sub AppStart (Args() As String)
' Init the BH1750 device with device address 0x23 or 0x5C and bus number 0 (Pi 1) or 1 (Pi 2,3)
If bh.Initialize(0x23, 1) = False Then Return
' Power on and set the measurement mode
bh.PowerOnSetMode(bh.CONTINUOUS_HIGH_RES_MODE_1)
Log("BH1750 Initialized")
' Get the first value
RequestTimer_Tick
' Init and start the request timer
RequestTimer.Initialize("RequestTimer", RequestInterval)
RequestTimer.Enabled = True
' Do not forget to start the message loop
StartMessageLoop
End Sub
' Handle timer requests
Sub RequestTimer_Tick
Log($"${DateTime.Time(DateTime.Now)} ${NumberFormat(bh.LightIntensity,0,0)} lux"$)
End Sub