Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit e38af8d

Browse files
committedOct 6, 2020
Digital out example
Digital out example expanded with description and toggle of all channels, including latch/retry options
1 parent 206a4d1 commit e38af8d

File tree

1 file changed

+93
-9
lines changed

1 file changed

+93
-9
lines changed
 
+93-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
/*
22
Automation Carrier - Digital Output Example
33
4-
This sketch shows how to send a value on the DIGITAL
5-
OUTPUTS channels on the Automation Carrier.
6-
4+
This sketch shows how to send values on the
5+
DIGITAL OUT channels on the Automation Carrier.
6+
Please remember that pin "24V IN" of the connector
7+
DIGITAL_OUTPUTS must be connected to 24V.
8+
The DIGITAL OUT channels are high side switches
9+
capable to handle up to 0.5A. There is an over current
10+
protection that open the channel when the current is
11+
above 0.7A with a +-20% tolerance.
12+
The over current protection can be set to have two
13+
different behaviors, and it is the same for all channels:
14+
1) Latch mode: when the over current is detected
15+
the channel is opened, and will remain opened until
16+
it will be toggle via software.
17+
2) Auto retry: when the over current is detected
18+
the channel is openend, but after some tents of
19+
milliseconds the channel will automatically try
20+
to close itself again. In case of a persistant
21+
overcurrent the channel will continuously toggle.
22+
723
The circuit:
824
- Portenta H7
925
- Automation Carrier
@@ -12,25 +28,93 @@
1228
by Silvio Navaretti
1329
modified 29 September 2020
1430
by Riccardo Rizzo
31+
modified 6 October 2020
32+
by Silvio Navaretti
1533
This example code is in the public domain.
1634
*/
35+
1736
#include <AutomationCarrier.h>
1837

1938
using namespace automation;
20-
uint16_t letture = 0;
2139

2240
void setup() {
2341
Serial.begin(9600);
42+
//The loop starts only when the serial monitor is opened.
2443
while (!Serial);
2544

26-
Serial.println("Digital out test");
27-
digital_outputs.setAll(0);
45+
//Set over current behavior of all channels to latch mode:
2846
programmable_digital_io.setLatch();
29-
// To write on a single channel use the API set(int channel_index, bool val)
30-
digital_outputs.setAll(255);
47+
//Set over current behavior of all channels to auto retry mode:
48+
programmable_digital_io.setRetry();
49+
50+
//At startup set all channels to OPEN
51+
digital_outputs.setAll(0);
3152
}
3253

3354

3455
void loop() {
56+
Serial.println("DIGITAL OUT:");
57+
58+
//Set all channels to CLOSED
59+
digital_outputs.setAll(255);
60+
Serial.print("All channels are CLOSED for 1s...");
61+
delay(1000);
62+
63+
//Set all channels to OPEN
64+
digital_outputs.setAll(0);
65+
Serial.println("now they are OPEN.");
66+
delay(1000);
3567

36-
}
68+
//Toggle each channel for 1s, one by one
69+
70+
digital_outputs.set(0, HIGH);
71+
Serial.print("CH0 is CLOSED for 1s...");
72+
delay(1000);
73+
digital_outputs.set(0, LOW);
74+
Serial.println("now is OPEN.");
75+
76+
digital_outputs.set(1, HIGH);
77+
Serial.print("CH1 is CLOSED for 1s...");
78+
delay(1000);
79+
digital_outputs.set(1, LOW);
80+
Serial.println("now is OPEN.");
81+
82+
digital_outputs.set(2, HIGH);
83+
Serial.print("CH2 is CLOSED for 1s...");
84+
delay(1000);
85+
digital_outputs.set(2, LOW);
86+
Serial.println("now is OPEN.");
87+
88+
digital_outputs.set(3, HIGH);
89+
Serial.print("CH3 is CLOSED for 1s...");
90+
delay(1000);
91+
digital_outputs.set(3, LOW);
92+
Serial.println("now is OPEN.");
93+
94+
digital_outputs.set(4, HIGH);
95+
Serial.print("CH4 is CLOSED for 1s...");
96+
delay(1000);
97+
digital_outputs.set(4, LOW);
98+
Serial.println("now is OPEN.");
99+
100+
digital_outputs.set(5, HIGH);
101+
Serial.print("CH5 is CLOSED for 1s...");
102+
delay(1000);
103+
digital_outputs.set(5, LOW);
104+
Serial.println("now is OPEN.");
105+
106+
digital_outputs.set(6, HIGH);
107+
Serial.print("CH6 is CLOSED for 1s...");
108+
delay(1000);
109+
digital_outputs.set(6, LOW);
110+
Serial.println("now is OPEN.");
111+
112+
digital_outputs.set(7, HIGH);
113+
Serial.print("CH7 is CLOSED for 1s...");
114+
delay(1000);
115+
digital_outputs.set(7, LOW);
116+
Serial.println("now is OPEN.");
117+
118+
Serial.println();
119+
delay(1000);
120+
}

0 commit comments

Comments
 (0)
This repository has been archived.