Sub Process_Globals
Public Serial1 As Serial
Public Timer1 As Timer
Public Interval As Int
Dim HUMIDITY,TEMPERATURE As Double
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Interval=2
Timer1.Initialize("Timer1_Tick",Interval*1000)
RunNative("setup",Null)
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
TEMPERATURE=0
RunNative("read",Null)
Log(" Temperature =",NumberFormat(TEMPERATURE,2,1), " ºC")
Log(" Humidity =",NumberFormat(HUMIDITY,2,1), " %RH")
End Sub
#if C
#include "DHT.h"
#define DHTPIN 22 // what digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
void setup(B4R::Object* o){
dht.begin();
}
void read (B4R::Object* o) {
b4r_main::_humidity = dht.readHumidity();
b4r_main::_temperature = dht.readTemperature();
}
#End if