Newer
Older
#include "pins.hpp"
MCP23S08 MCP(SS, MISO, MOSI, SCK);
volatile byte ISR_FLAG = 0;
struct pins PINS;
void initializeMCP() {
pinMode(ISR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ISR_PIN), isr, CHANGE);
// Enable inputs and interrupts on pins 0-2
MCP.pinMode8(0b00000111);
MCP.enableInterrupt(0, CHANGE);
MCP.enableInterrupt(1, CHANGE);
MCP.enableInterrupt(2, CHANGE);
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, BIN);
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;
PINS.sib = false;
PINS.plc = false;
PINS.ups = false;
PINS.last_triggered = millis();
int regval = MCP.read8();
}
mask = 1 << 1;
if (!(regval & mask)) {
}
mask = 1 << 2;
if (!(regval & mask)) {
bool on = true;
unsigned long toggle_start = 0;
void toggle_status_led() {