Update examples

This commit is contained in:
Henrik Ekblad
2015-09-19 23:54:35 +02:00
parent 9ed25eb8dc
commit 96f702fa4f
44 changed files with 970 additions and 764 deletions
@@ -39,15 +39,19 @@
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
#include <SPI.h>
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensor.h>
#include <Time.h>
#include <DS3232RTC.h> // A DS3231/DS3232 library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
MySensor gw;
boolean timeReceived = false;
unsigned long lastUpdate=0, lastRequest=0;
@@ -57,16 +61,14 @@ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("RTC Clock", "1.0");
sendSketchInfo("RTC Clock", "1.0");
// the function to get the time from the RTC
setSyncProvider(RTC.get);
// Request latest time from controller at startup
gw.requestTime(receiveTime);
requestTime(receiveTime);
// initialize the lcd for 16 chars 2 lines and turn on backlight
lcd.begin(16,2);
@@ -84,7 +86,6 @@ void receiveTime(unsigned long controllerTime) {
void loop()
{
unsigned long now = millis();
gw.process();
// If no time has been received yet, request it every 10 second from controller
// When time has been received, request update every hour
@@ -92,7 +93,7 @@ void loop()
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
// Request time from controller.
Serial.println("requesting time");
gw.requestTime(receiveTime);
requestTime(receiveTime);
lastRequest = now;
}