-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiple.ino
More file actions
78 lines (59 loc) · 2.02 KB
/
Multiple.ino
File metadata and controls
78 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SA van der Wulp | April 14, 2025
// Copyright (c) 2025 | MIT License
// https://vdwulp.github.io/iButtonTag
// Include the library
#include <iButtonTag.h>
// Data wire of the iButton probe is connected to pin 2 on the Arduino
#define PIN_PROBE 2
// Setup iButtonTag on the pin
iButtonTag ibutton( PIN_PROBE );
/*
* The setup function.
*/
void setup( void ) {
// Start serial port
Serial.begin( 9600 );
Serial.println( "iButtonTag Library Demo" );
}
/*
* Main function, read identification code of possibly _multiple_ iButton tags.
*
* It's possible to connect multiple iButton probes to the same data line pin
* and ground. If there are multiple probes connected there is a chance multiple
* iButtons are presented at the same time. In this case the identification
* codes must be read in a different way.
*/
void loop(void)
{
// Variable to store identification code
iButtonCode code;
// Start the search for identification codes
Serial.println( "Reading... " );
int8_t status = ibutton.readCodes(); // The plural _codes_ in this function
// name indicates we're searching for
// (possibly) multiple codes.
if ( status == 0 ) {
Serial.println("No iButton detected");
return;
}
// Keep trying to get next code until status indicates there are no more codes
while ( status = ibutton.nextCode( code ) != 0 ) {
// Variable _status_ will now indicate success/failure
switch( status ) {
case 1: // Success
Serial.print( "iButton code read successfully: " );
ibutton.printCode( code ); // Variable _code_ contains the ID-code
Serial.println();
break;
case 0: // No iButton
Serial.println( "No iButton detected" );
break;
case -1: // Checksum failed
case -2: // Code all zeros
Serial.println( "iButton code invalid" );
break;
default: // Unknown, shouldn't happen
Serial.println( "Unknown status" );
}
}
}