Newer
Older
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
#include "pins.hpp"
MCP23S08 MCP(SS, MISO, MOSI, SCK);
volatile byte ISR_FLAG = 0;
struct pins PINS;
void IRAM_ATTR isr(){
ISR_FLAG = 1;
}
void initializeMCP()
{
pinMode(ISR_PIN, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(ISR_PIN), isr, CHANGE);
attachInterrupt(digitalPinToInterrupt(TRIGGER_SIGNAL), isr, CHANGE);
SPI.begin();
MCP.begin();
// Enable inputs and interrupts on pins 0-2
MCP.pinMode8(0b00000111);
MCP.enableInterrupt(0, FALLING);
MCP.enableInterrupt(1, FALLING);
MCP.enableInterrupt(2, FALLING);
Serial.println("MCP23S08 Started");
}
void isr_check_loop()
{
if (ISR_FLAG == 1){
PINS.sib = false;
PINS.plc = false;
PINS.ups = false;
PINS.last_triggered = millis();
Serial.print("Interrupt: ");
uint8_t regval = MCP.getInterruptCaptureRegister(); //INTCAP
Serial.print(regval);
uint8_t mask = 1 << 0;
if (!(regval & mask)) {
Serial.print("UPS");
PINS.ups = true;
}
mask = 1 << 1;
if (!(regval & mask)) {
Serial.print("PLC");
PINS.plc = true;
}
mask = 1 << 2;
if (!(regval & mask)) {
Serial.print("SIB");
PINS.sib = true;
}
Serial.println();
ISR_FLAG = 0;
}
}
bool on = true;
unsigned long toggle_start = 0;
void toggle_status_led() {
if (millis() - toggle_start >= 1000) {
toggle_start = millis();
on = !on;