forked from arduino-libraries/Arduino_MachineControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigital_input.ino
75 lines (58 loc) · 2.5 KB
/
Digital_input.ino
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
/*
* Portenta Machine Control - Digital Input Example
*
* This sketch shows how to periodically read from all the DIGITAL INPUTS channels on the Machine Control.
*
* Circuit:
* - Portenta H7
* - Portenta Machine Control
*
* Initial author: Riccardo Rizzo @Rocketct
*/
#include <Arduino_MachineControl.h>
uint16_t readings = 0;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
Wire.begin();
if (!MachineControl_DigitalInputs.begin()) {
Serial.println("Digital input GPIO expander initialization fail!!");
}
}
void loop() {
//Reads and Prints all channels (in a single operation)
readAll();
//Read one-by-one each channel and print them one-by-one
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_00);
Serial.println("CH00: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_01);
Serial.println("CH01: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_02);
Serial.println("CH02: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_03);
Serial.println("CH03: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_04);
Serial.println("CH04: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_05);
Serial.println("CH05: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_06);
Serial.println("CH06: "+String(readings));
readings = MachineControl_DigitalInputs.read(DIN_READ_CH_PIN_07);
Serial.println("CH07: "+String(readings));
Serial.println();
delay(250);
}
uint8_t readAll() {
uint32_t inputs = MachineControl_DigitalInputs.readAll();
Serial.println("CH00: " + String((inputs & (1 << DIN_READ_CH_PIN_00)) >> DIN_READ_CH_PIN_00));
Serial.println("CH01: " + String((inputs & (1 << DIN_READ_CH_PIN_01)) >> DIN_READ_CH_PIN_01));
Serial.println("CH02: " + String((inputs & (1 << DIN_READ_CH_PIN_02)) >> DIN_READ_CH_PIN_02));
Serial.println("CH03: " + String((inputs & (1 << DIN_READ_CH_PIN_03)) >> DIN_READ_CH_PIN_03));
Serial.println("CH04: " + String((inputs & (1 << DIN_READ_CH_PIN_04)) >> DIN_READ_CH_PIN_04));
Serial.println("CH05: " + String((inputs & (1 << DIN_READ_CH_PIN_05)) >> DIN_READ_CH_PIN_05));
Serial.println("CH06: " + String((inputs & (1 << DIN_READ_CH_PIN_06)) >> DIN_READ_CH_PIN_06));
Serial.println("CH07: " + String((inputs & (1 << DIN_READ_CH_PIN_07)) >> DIN_READ_CH_PIN_07));
Serial.println();
}