Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Arduino.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 #include "Software/OWI.h"
4 #include "Driver/Arduino.h"
5 #include "assert.h"
6 #include "benchmark.h"
7 
8 // One-Wire Interface Remote Arduino (Master)
10 Arduino arduino(owi);
11 
12 void setup()
13 {
14  Serial.begin(57600);
15  while (!Serial);
16 
17  uint8_t rom[owi.ROM_MAX] = { 0 };
18  int8_t last = owi.FIRST;
19  int id = 0;
20  int pins;
21 
22  // Search for device and set short address (label)
23  last = owi.search_rom(arduino.FAMILY_CODE, rom, last);
24  ASSERT(last != owi.ERROR);
25  arduino.rom(rom);
26  arduino.label_rom(id);
27  Serial.print(id);
28  Serial.print(':');
30  Serial.println();
31 
32  // Get number of digital pins and read pin state
33  ASSERT((pins = arduino.num_digital_pins()) > 0);
34  Serial.print(F("arduino.num_digital_pins="));
35  Serial.println(pins);
36  Serial.println(F("arduino.digitalRead:"));
37  for (int i = 0; i < pins; i++) {
38  Serial.print('D');
39  Serial.print(i);
40  Serial.print(':');
41  Serial.println(arduino.digitalRead(i));
42  }
43 
44  // Get number of analog inputs and read analog values
45  ASSERT((pins = arduino.num_analog_inputs()) > 0);
46  Serial.print(F("arduino.num_analog_inputs="));
47  Serial.println(pins);
48  Serial.println(F("arduino.analogRead:"));
49  for (int i = 0; i < pins; i++) {
50  Serial.print('A');
51  Serial.print(i);
52  Serial.print(':');
53  Serial.println(arduino.analogRead(i));
54  }
55 
56  // Set builtin led pin to output
57  ASSERT(arduino.pinMode(13, OUTPUT) == 0);
58 
59  // Set pulse width modulated pin(3) to 50% duty(127)
60  ASSERT(arduino.analogWrite(3, 127) == 0);
61 }
62 
63 void loop()
64 {
65  // Classical blink sketch loop; measure micro-seconds to perform
66  // one-wire interface remote arduino functions
67  MEASURE(arduino.digitalWrite(13, HIGH));
68  delay(1000);
69  MEASURE(arduino.digitalWrite(13, LOW));
70  delay(1000);
71 }
Software::OWI< BOARD::D7 > owi
Definition: Arduino.ino:9
int print_rom(Print &out=Serial)
Definition: Arduino.h:202
Error during search.
Definition: OWI.h:192
static const uint8_t FAMILY_CODE
Definition: Arduino.h:38
void setup()
Definition: Arduino.ino:12
int num_digital_pins()
Definition: Arduino.h:152
int label_rom(uint8_t nr)
Definition: Arduino.h:188
int digitalWrite(int pin, int value)
Definition: Arduino.h:105
int8_t search_rom(uint8_t family, uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:204
Software::Serial< BOARD::D0 > Serial
Definition: Alarm.ino:8
int num_analog_inputs()
Definition: Arduino.h:164
int analogWrite(int pin, int duty)
Definition: Arduino.h:138
int digitalRead(int pin)
Definition: Arduino.h:90
void rom(const uint8_t *rom)
Definition: OWI.h:303
int analogRead(int pin)
Definition: Arduino.h:120
Arduino arduino(owi)
Start position of search.
Definition: OWI.h:191
int pinMode(int pin, int mode)
Definition: Arduino.h:76
static const size_t ROM_MAX
Definition: OWI.h:32
void loop()
Definition: Arduino.ino:63