Is there a way to use and interrupt pin to change your case switch within your main loop? IN my code you see that interrupt pin 2 calls void(interruptOne). In interruptOne I have an if statement IF (2 differtn buttons are high at same time, then switch case from S_statup to S_coldLow. Problem is that it doesn't switch. How do I make this work? I want to use the interrupt pin so that I don't have to call digitalRead constantly checking the pin
const int S_startup = 1;
const int S_coldLow = 2;
const byte interruptPin = 2;
int buttons = 1;
volatile byte state = LOW;
int changePin = 7;
int changePinState = 0;
int pinState = 0;
long debouncing_time = 15; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
const int ledPin = 11;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), interruptOne, FALLING);
pinMode(changePin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int states = S_startup;
//////////////////////////////////////////////////////////////////////
// if(buttons==1){Serial.println("I got seven to go low and now 1");}
//if(buttons==2){Serial.println("I got seven to go low and now 2");}
//if(buttons==3){Serial.println("I got seven to go low and now 3");}
//if(buttons==4){buttons=1;}
///////////////////////////////////////////////////////////////////
//static int states = S_startup;
switch (states) {
case S_startup: {
Serial.println("WE ARE IN startup STATE");
} break;
case S_coldLow: {
Serial.println("WE ARE IN coldLow STATE");
} break;
}//END CASES
}//END LOOP
void interruptOne() {
changePinState = digitalRead(changePin);
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 300)
{
if (changePinState == LOW) {
buttons++;
int states = S_coldLow;
}
}
last_interrupt_time = interrupt_time;
}
void Interrupt() {
buttons++;
delay(10000);
}