Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Search.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 #include "Software/OWI.h"
4 #include "Software/Serial.h"
5 #include "assert.h"
6 
7 Software::Serial<BOARD::D0> Serial;
9 
10 void setup()
11 {
12  Serial.begin(57600);
13  while (!Serial);
14 }
15 
16 void loop()
17 {
18  // Scan one-wire bus and print rom code for all detected devices
19  // on binary format and indicate discrepancy position.
20  uint8_t rom[owi.ROM_MAX] = { 0 };
21  int8_t last = owi.FIRST;
22  int i = 0;
23  do {
24  last = owi.search_rom(0, rom, last);
25  if (last == owi.ERROR) break;
26  Serial.print(i++);
27  Serial.print(':');
28  int8_t pos = 0;
29  for (size_t i = 0; i < sizeof(rom); i++)
30  for (uint8_t mask = 0x80; mask != 0; mask >>= 1, pos++) {
31  Serial.print((rom[i] & mask) != 0);
32  if (pos == last) Serial.print('*');
33  }
34  if (pos == last) Serial.print('*');
35  Serial.println();
36  } while (last != owi.LAST);
37  Serial.println();
38 
39  delay(5000);
40 }
Software::Serial< BOARD::D0 > Serial
Definition: Search.ino:7
Error during search.
Definition: OWI.h:192
void setup()
Definition: Search.ino:10
int8_t search_rom(uint8_t family, uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:204
Software::OWI< BOARD::D1 > owi
Definition: Search.ino:8
Last position, search completed.
Definition: OWI.h:193
Start position of search.
Definition: OWI.h:191
static const size_t ROM_MAX
Definition: OWI.h:32
void loop()
Definition: Search.ino:16