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