1
1
/*
2
2
Automation Carrier - Digital Output Example
3
3
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
+
7
23
The circuit:
8
24
- Portenta H7
9
25
- Automation Carrier
12
28
by Silvio Navaretti
13
29
modified 29 September 2020
14
30
by Riccardo Rizzo
31
+ modified 6 October 2020
32
+ by Silvio Navaretti
15
33
This example code is in the public domain.
16
34
*/
35
+
17
36
#include < AutomationCarrier.h>
18
37
19
38
using namespace automation ;
20
- uint16_t letture = 0 ;
21
39
22
40
void setup () {
23
41
Serial.begin (9600 );
42
+ // The loop starts only when the serial monitor is opened.
24
43
while (!Serial);
25
44
26
- Serial.println (" Digital out test" );
27
- digital_outputs.setAll (0 );
45
+ // Set over current behavior of all channels to latch mode:
28
46
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 );
31
52
}
32
53
33
54
34
55
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 );
35
67
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