Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelpatel committed Oct 9, 2017
1 parent 1b4e7c1 commit 4d6cfe1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
20 changes: 7 additions & 13 deletions examples/Alarm/Alarm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@ 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 @@ -59,7 +51,8 @@ void loop()
int8_t last = owi.FIRST;
uint8_t* rom = sensor.rom();
bool triggered = false;
static uint32_t timestamp = 0;
static uint16_t timestamp = 0;
uint8_t id = 0;
if (!sensor.convert_request(true)) return;
delay(sensor.conversion_time());
do {
Expand All @@ -68,15 +61,16 @@ void loop()
triggered = true;
sensor.read_scratchpad(false);
Serial.print(timestamp);
Serial.print(F(", "));
for (size_t i = 1; i < owi.ROM_MAX - 1; i++) {
Serial.print('.');
Serial.print(id++);
Serial.print(F(":rom="));
for (size_t i = 1; i < owi.ROM_MAX; i++) {
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);
}
Serial.print(F(", "));
Serial.print(F(",temperature="));
Serial.println(sensor.temperature());
} while (last != owi.LAST);
if (triggered) Serial.println();
timestamp += 1;
delay(1000);
}
17 changes: 7 additions & 10 deletions examples/DS18B20/DS18B20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ void loop()

// Print sequence number
Serial.print(id++);
Serial.print(F(": "));

// Print family code
Serial.print(F("family="));
Serial.print(F(":family="));
Serial.print(rom[0], HEX);

// Print serial number
Serial.print(F(", sn="));
Serial.print(F(",sn="));
size_t i = 1;
do {
if (rom[i] < 0x10) Serial.print(0);
Expand All @@ -69,25 +68,23 @@ void loop()
} while (i < owi.ROM_MAX - 1);

// Print cyclic redundancy check sum
Serial.print(F(", crc="));
Serial.print(F(",crc="));
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);

// Print conversion resolution
Serial.print(F(", resolution="));
Serial.print(F(",resolution="));
Serial.print(sensor.resolution());

// Print alarm trigger threshols
Serial.print(F(", trigger=["));
Serial.print(F(",trigger=["));
Serial.print(low);
Serial.print(F(".."));
Serial.print(high);

// And temperature
Serial.print(F("], temperature="));
Serial.print(sensor.temperature());
Serial.println(F(" C"));

Serial.print(F("],temperature="));
Serial.println(sensor.temperature());
} while (last != owi.LAST);

Serial.println();
Expand Down
8 changes: 3 additions & 5 deletions examples/Scanner/Scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ void loop()

// Print sequence number
Serial.print(id++);
Serial.print(F(": "));

// Print family code
Serial.print(F("family="));
Serial.print(F(":family="));
Serial.print(rom[0], HEX);

// Print serial number
Serial.print(F(", sn="));
Serial.print(F(",sn="));
size_t i = 1;
do {
if (rom[i] < 0x10) Serial.print(0);
Expand All @@ -57,10 +56,9 @@ void loop()
} while (i < owi.ROM_MAX - 1);

// Print cyclic redundancy check sum
Serial.print(F(", crc="));
Serial.print(F(",crc="));
if (rom[i] < 0x10) Serial.print(0);
Serial.println(rom[i], HEX);

} while (last != owi.LAST);

Serial.println();
Expand Down

0 comments on commit 4d6cfe1

Please sign in to comment.