Skip to content

Instantly share code, notes, and snippets.

@kfigiela
Created January 23, 2014 01:00
Show Gist options
  • Save kfigiela/8570788 to your computer and use it in GitHub Desktop.
Save kfigiela/8570788 to your computer and use it in GitHub Desktop.
idDHTLib for mbed example
Ticker dhtTicker, lcdTicker;
void dhtWrapper();
idDHTLib DHTLib(PTD7, dhtWrapper);
void dhtWrapper(){
DHTLib.dht22Callback(); // change do dht11Callback if needed
}
void readDht() {
if(!DHTLib.acquiring()) DHTLib.acquire();
}
void updateDisplay() {
float humidity = DHTLib.getHumidity();
printf("%f\n", humidity);
// ... update LCD or sth
}
int main() {
dhtTicker.attach(&readDht, 3.0); // DHT's can be read no more often than every 2s if I remember correctly
lcdTicker.attach(&updateDisplay, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment