Wow, thank you so much for your thorough answers!
@Nominal Animal: Your answer goes a little beyond the scope of my little problem, but I'll definitively keep it in mind for later polishing of the project-- I want to simply be able to disable the stepper drivers at any time. When I do it while the steppers are in motion, they'll loose their position and that is where your approach would make an excellent solution.
I was not aware that there is only one interrupt per pin, but the use of CHANGE might just cover everything needed. And I'll make shure not to have the fate of mankind be dependent solely on my code, I swear =)
So, here's what works for me:
somewhere early:
Code:
#define SafeOffPin 10 // Int
volatile bool safeOffState; // Store the SafeOff Btn state
In setup()
Code:
pinMode(SafeOffPin, INPUT_PULLUP);
attachInterrupt(SafeOffPin, offChange, CHANGE);
somewhere else:
Code:
void offChange(){
if(debug) Serial.println("offChange");
if(!digitalRead(SafeOffPin)){ // [Machine ON] (knob right)
if(safeOffState){ // Was [OFF] before
if(debug) Serial.println("Machine ON");
digitalWrite(ALL_EN_PIN, LOW); // Enable stepper drivers
mcp.digitalWrite(powerLED, HIGH);
mcp.digitalWrite(InOutLED, HIGH);
updateLcd(0,true); // draw all items
safeOffState = false;
}
}
else{ // [Machine OFF] (knob left)
if(!safeOffState){ // Was [ON] before
if(debug) Serial.println("Machine SoftOFF");
digitalWrite(ALL_EN_PIN, HIGH); // Disable stepper drivers
mcp.digitalWrite(powerLED, LOW);
mcp.digitalWrite(InOutLED, LOW);
updateLcd(24, true); // Msg: "save to cut power now"
safeOffState = true;
}
}
}