Thanks for taking a look!
Hardware for this project is a Nano, but if different hardware would make this easier, I'm open to suggestions.
The desire on this sketch is to have two buttons, the first one pressed will light an LED, and disable the other button. A 3rd button will re-enable the buttons.
Everything works, except for the re-enable part - I see the button press, and an LED blink confirms it's in the part of the code to re-enable, but the buttons don't come active.
I've tried cli()/sei() and attach/detach interrupts, neither of which worked out well, generally gave compile errors due to hardware.
Thanks for your input, I appreciate it.
Code Below:
#define EI_ARDUINO_INTERRUPTED_PIN
#include <EnableInterrupt.h>
#include <avr/power.h>
#define D10 13
#define D11 14
#define D12 15
void blink13(int len){
digitalWrite(13, HIGH);
for (int x=1; x<len; x++){
delay(1000); // Gets ignored for some reason
}
digitalWrite(13, LOW);
}
void interruptFunction() {
switch(arduinoInterruptedPin){
case 13:
// Reset Button pressed
enableInput();
break;
case 14:
// Player 1 Wins!
disableInput();
blink13(100);
break;
case 15:
// Player 2 Wins!
disableInput();
blink13(100);
break;
default:
blink13(10);
break;
}
}
void setup() {
clock_prescale_set(clock_div_1);
pinMode(D10, INPUT_PULLUP); // Reset
pinMode(D11, INPUT_PULLUP); // Player 1
pinMode(D12, INPUT_PULLUP); // Player 2
enableInterrupt(D10, interruptFunction, CHANGE);
enableInterrupt(D11, interruptFunction, CHANGE);
enableInterrupt(D12, interruptFunction, CHANGE);
digitalWrite(13, LOW); // turn the LED off
}
void enableInput(){
digitalWrite(arduinoInterruptedPin, HIGH);
blink13(50);
//pinMode(D10, INPUT_PULLUP); // Reset //Should be enabled already
pinMode(D11, INPUT_PULLUP); // Player 1
pinMode(D12, INPUT_PULLUP); // Player 2
blink13(50);
//enableInterrupt(D10, interruptFunction, CHANGE); // Should be enabled already
enableInterrupt(D11, interruptFunction, CHANGE);
enableInterrupt(D12, interruptFunction, CHANGE);
blink13(200);
}
void disableInput(){
// disableInterrupt(D10); // Don't disable the Admin!
disableInterrupt(D11); // Disable Player1
disableInterrupt(D12); // Disable Player 2
}
void loop() {
}