Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelpatel committed Oct 5, 2017
1 parent 91a1b3c commit a732841
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions examples/Alarm/Alarm.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "RTC.h"
#include "GPIO.h"
#include "OWI.h"
#include "Software/OWI.h"
Expand All @@ -13,7 +12,6 @@ Software::OWI<BOARD::D7> owi;
#endif

DS18B20 sensor(owi);
RTC rtc;

void setup()
{
Expand All @@ -24,13 +22,21 @@ void setup()
// Iterate though all thermometers and configure.
uint8_t* rom = sensor.rom();
int8_t last = owi.FIRST;
Serial.println(F("Sensors:"));
do {
last = owi.search_rom(sensor.FAMILY_CODE, rom, last);
if (last == owi.ERROR) break;
sensor.resolution(10);
sensor.set_trigger(20, 25);
sensor.write_scratchpad();
for (size_t i = 1; i < owi.ROM_MAX - 1; i++) {
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);
}
Serial.println();
} while (last != owi.LAST);
Serial.println();
Serial.println(F("Alarms:"));
}

void loop()
Expand All @@ -42,28 +48,24 @@ void loop()
int8_t last = owi.FIRST;
uint8_t* rom = sensor.rom();
bool triggered = false;

if (!rtc.tick()) return;
static uint32_t timestamp = 0;
if (!sensor.convert_request(true)) return;
delay(1000);
do {
last = owi.alarm_search(rom, last);
if (last == owi.ERROR) break;
triggered = true;
sensor.read_scratchpad(false);
if (!triggered) {
char daytime[32];
struct tm now;
rtc.get_time(now);
isotime_r(&now, daytime);
Serial.print(daytime + 11);
triggered = true;
}
Serial.print(timestamp);
Serial.print(F(", "));
for (size_t i = 1; i < owi.ROM_MAX - 1; i++) {
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);
}
Serial.print(F(", "));
Serial.print(sensor.temperature());
Serial.println(sensor.temperature());
} while (last != owi.LAST);
if (triggered) Serial.println();
timestamp += 1;
delay(1000);
}

0 comments on commit a732841

Please sign in to comment.