Skip to content

Commit 4a39d8b

Browse files
committed
1-Wire Search
1 parent f5aff81 commit 4a39d8b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

examples/Search/Search.ino

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "OWI.h"
2+
#include "GPIO.h"
3+
#include "Software/OWI.h"
4+
5+
#if defined(ARDUINO_attiny)
6+
#include "Software/Serial.h"
7+
Software::Serial<BOARD::D0> Serial;
8+
Software::OWI<BOARD::D1> owi;
9+
#else
10+
Software::OWI<BOARD::D7> owi;
11+
#endif
12+
13+
void setup()
14+
{
15+
Serial.begin(57600);
16+
while (!Serial);
17+
}
18+
19+
void loop()
20+
{
21+
uint8_t rom[owi.ROM_MAX] = { 0 };
22+
int8_t last = owi.FIRST;
23+
24+
// Scan one-wire bus and print rom code for all detected devices
25+
do {
26+
last = owi.search_rom(0, rom, last);
27+
if (last == owi.ERROR) break;
28+
for (size_t i = 0; i < sizeof(rom); i++)
29+
for (uint8_t mask = 0x80; mask != 0; mask >>= 1)
30+
Serial.print(rom[i] & mask ? '1' : '0' );
31+
Serial.println();
32+
for (int i = 0; i < last - 1; i++) Serial.print('-');
33+
Serial.println('*');
34+
} while (last != owi.LAST);
35+
Serial.println();
36+
37+
delay(5000);
38+
}

0 commit comments

Comments
 (0)