Files
MySensors/libraries/MySensors/examples/TimeAwareSensor/TimeAwareSensor.ino
T
Henrik Ekblad c332667a8d RF24 moved to utility folder of library. This results in one less include in sketches!
Serial flush in sleep method also means one less code in examples.
Removed set(bool) in message. Not needed. getBool just calls getInt
__attribute__((packed)) for RPI compability
Print more info in send/read debug prints.
Get internalTemp returns full degrees and uses longer Vref delay
Fix debug print gateway prepend (wrong command/type)
Fixed problem in RelayWithButton example. Now working with ack in both directions.
Serial protocol changed (incoming serial message have an new ack-parameter)
2014-06-17 22:16:38 +02:00

56 lines
1.1 KiB
Arduino

// Example sketch showing how to request time from controller
#include <SPI.h>
#include <MySensor.h>
#include <Time.h>
MySensor gw;
boolean timeReceived = false;
void setup()
{
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Clock", "1.0");
// Request time from controller.
gw.requestTime(receiveTime);
}
// This is called when a new time value was received
void receiveTime(unsigned long time) {
// Ok, set incoming time
setTime(time);
timeReceived = true;
}
void loop()
{
gw.process();
// Print time
if (timeReceived) {
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}