Fix compiler error and generally clean up TimeRTCLog example

This commit is contained in:
PaulStoffregen
2017-09-05 02:07:02 -07:00
parent 01083f838c
commit 420a3c08af

View File

@ -1,5 +1,5 @@
/*
* TimeRTCLogger.pde
* TimeRTCLogger.ino
* example code illustrating adding and subtracting Time.
*
* this sketch logs pin state change events
@ -28,17 +28,16 @@ void setup() {
void loop()
{
for(int i=0; i < nbrInputPins; i++)
{
for (int i=0; i < nbrInputPins; i++) {
boolean val = digitalRead(inputPins[i]);
if(val != state[i])
{
if (val != state[i]) {
time_t duration = 0; // the time since the previous event
state[i] = val;
time_t timeNow = now();
if(prevEventTime[i] > 0)
if (prevEventTime[i] > 0) {
// if this was not the first state change, calculate the time from the previous change
duration = duration = timeNow - prevEventTime[i];
duration = timeNow - prevEventTime[i];
}
logEvent(inputPins[i], val, timeNow, duration ); // log the event
prevEventTime[i] = timeNow; // store the time for this event
}
@ -49,10 +48,11 @@ void logEvent( int pin, boolean state, time_t timeNow, time_t duration)
{
Serial.print("Pin ");
Serial.print(pin);
if( state == HIGH)
if (state == HIGH) {
Serial.print(" went High at ");
else
} else {
Serial.print(" went Low at ");
}
showTime(timeNow);
if (duration > 0) {
// only display duration if greater than 0
@ -63,7 +63,8 @@ void logEvent( int pin, boolean state, time_t timeNow, time_t duration)
}
void showTime(time_t t){
void showTime(time_t t)
{
// display the given time
Serial.print(hour(t));
printDigits(minute(t));
@ -84,7 +85,8 @@ void printDigits(int digits){
Serial.print(digits);
}
void showDuration(time_t duration){
void showDuration(time_t duration)
{
// prints the duration in days, hours, minutes and seconds
if (duration >= SECS_PER_DAY) {
Serial.print(duration / SECS_PER_DAY);