-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCP23017.ino
128 lines (104 loc) · 2.84 KB
/
MCP23017.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifdef ENABLE_EIO
#include <Adafruit_MCP23017.h>
Adafruit_MCP23017 mcp;
// Interrupts from the MCP will be handled by this PIN
byte arduinoIntPin=2;
// ... and this interrupt vector
byte arduinoInterrupt=1;
byte SelectedPin;
void eio_start() {
pinMode(arduinoIntPin,INPUT);
mcp.begin(); // use default address 0
// We mirror INTA and INTB, so that only one line is required between MCP and Arduino for int reporting
// The INTA/B will not be Floating
// INTs will be signaled with a LOW
mcp.setupInterrupts(true,false,LOW);
Serial.println(F("<EIO_START=DONE>"));
}
void intCallBack(){
awakenByInterrupt=true;
}
void handleInterrupt(){
// Get more information from the MCP from the INT
uint8_t pin=mcp.getLastInterruptPin();
uint8_t val=mcp.getLastInterruptPinValue();
//seria print?
cleanInterrupts();
}
void cleanInterrupts(){
EIFR=0x01;
awakenByInterrupt=false;
}
void eio_cmd(uint8_t Setting) {
switch (Setting) {
case 0: //pinmode
Serial.print(F("<EIO_PM="));
if (value_string == "OUT") {
mcp.pinMode(SelectedPin, OUTPUT);
Serial.print(F("OUT"));
}else{
mcp.pinMode(SelectedPin, INPUT);
Serial.print(F("IN"));
}
Serial.println(F(">"));
break;
case 1:https://digwrite
Serial.print(F("<EIO_DW="));
if (value_string == "HIGH") {
mcp.digitalWrite(SelectedPin, HIGH);
Serial.print(F("HIGH"));
}else{
mcp.digitalWrite(SelectedPin, LOW);
Serial.print(F("LOW"));
}
Serial.println(F(">"));
break;
case 2:https://digread
Serial.print(F("<EIO_DR="));
Serial.print(mcp.digitalRead(SelectedPin));
Serial.println(F(">"));
break;
case 3:https://pullup
Serial.print(F("<EIO_PU="));
if (value_string == "ON") {
mcp.pullUp(SelectedPin, HIGH);
Serial.print(F("ON"));
}else{
mcp.pullUp(SelectedPin, LOW);
Serial.print(F("OFF"));
}
Serial.println(F(">"));
break;
case 4:https://readall
Serial.print(F("<EIO_RALL="));
Serial.print(mcp.readGPIOAB(),HEX);
Serial.println(F(">"));
break;
case 5:https://writeall
mcp.writeGPIOAB(value_string.toInt());
Serial.print(F("<EIO_WALL="));
Serial.print(value_string.toInt());
Serial.println(F(">"));
break;
case 6:https://enable int
Serial.print(F("<EIO_INT="));
if (value_string == "TRUE") {
attachInterrupt(arduinoInterrupt,intCallBack,FALLING);
Serial.print(F("ON"));
}else{
detachInterrupt(arduinoInterrupt);
Serial.print(F("OFF"));
}
Serial.println(F(">"));
break;
case 7:
SelectedPin = value_string.toInt();
Serial.print(F("<EIO_SPIN="));
Serial.print(SelectedPin);
Serial.println(F(">"));
break;
case 8:https://
break;
}
}
#endif