This code reads a simple temperature value from DHT11 then send via RF24 in every 5 secs.

Dependencies:   DHT11 RF24_fork WakeUp mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "config.h"
00003 #include "RF24.h"
00004 #include "WakeUp.h"
00005 #include "Dht11.h"
00006 
00007 DigitalOut myled(ledpin);
00008 Dht11 sensor(RXD);
00009 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
00010 
00011 
00012 const int hb = 9999;
00013 void RadioSetup();
00014 
00015 int main(){
00016     int s;
00017     int temp = 0;
00018     myled=1;
00019     RadioSetup();
00020     radio.stopListening();
00021     myled=0;
00022     
00023      while(1){
00024         
00025         WakeUp::set_ms(5000);
00026         myled=1;
00027         deepsleep();
00028         myled=0;
00029          
00030         sensor.read();
00031         temp=getCelsius();
00032         radio.powerUp();
00033         radio.write(&temp, 4);
00034         radio.powerDown();
00035     }
00036 }
00037     
00038     void RadioSetup(){
00039     radio.begin();
00040     radio.setPALevel(RF24_PA_LOW);
00041     radio.setChannel(RadioChannel);
00042     radio.setRetries(0,2);
00043     radio.enableDynamicAck();
00044     radio.enableDynamicPayloads();
00045     radio.openWritingPipe(DataAddress);
00046     }