This code reads a simple temperature value from DHT11 then send via RF24 in every 5 secs.
Dependencies: DHT11 RF24_fork WakeUp mbed
Diff: main.cpp
- Revision:
- 0:49273053c399
diff -r 000000000000 -r 49273053c399 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 03 17:13:20 2018 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "config.h" +#include "RF24.h" +#include "WakeUp.h" +#include "Dht11.h" + +DigitalOut myled(ledpin); +Dht11 sensor(RXD); +RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN ); + + +const int hb = 9999; +void RadioSetup(); + +int main(){ + int s; + int temp = 0; + myled=1; + RadioSetup(); + radio.stopListening(); + myled=0; + + while(1){ + + WakeUp::set_ms(5000); + myled=1; + deepsleep(); + myled=0; + + sensor.read(); + temp=getCelsius(); + radio.powerUp(); + radio.write(&temp, 4); + radio.powerDown(); + } +} + + void RadioSetup(){ + radio.begin(); + radio.setPALevel(RF24_PA_LOW); + radio.setChannel(RadioChannel); + radio.setRetries(0,2); + radio.enableDynamicAck(); + radio.enableDynamicPayloads(); + radio.openWritingPipe(DataAddress); + } \ No newline at end of file