Here's the buttonTest sketch I've been using to test the buttons and interrupts:
/*
A test program to test the interrupt function with buttons.
*/
#include "NEWLedControl.h"
LedControl lc=LedControl(12,11,10,4);
volatile int ledState;
boolean breakLoopFlag;
byte currentLED[32];
const int sizeOfClearScreen = 32;
byte ClearScreen[sizeOfClearScreen] = {
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
;
const int sizeOfSmiley = 32;
byte Smiley[sizeOfSmiley] = {
B00000000,B00000000,B00000000,B00000000,B00111000,B00111000,B00111000,B00000000,
B00000000,B00111000,B00111000,B00111000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00111000,B01111000,B11111000,B11111000,B11111000,
B11111000,B11111000,B11111000,B01111000,B00111000,B00000000,B00000000,B00000000};
;
const int sizeOfHearts = 32;
byte Heart1[sizeOfHearts] = {
B00000000,B00000000,B00000000,B11000000,B11100000,B11110000,B11110000,B11100000,
B11000000,B11100000,B11110000,B11110000,B11100000,B11000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00001000,B00011000,B00111000,B01111000,
B11111000,B01111000,B00111000,B00011000,B00001000,B00000000,B00000000,B00000000};
;
byte Heart2[sizeOfHearts] = {
B00000000,B00000000,B11000000,B11100000,B11110000,B11111000,B11111000,B11110000,
B11100000,B11110000,B11111000,B11111000,B11110000,B11100000,B11000000,B00000000,
B00000000,B00000000,B00000000,B00001000,B00011000,B00111000,B01111000,B11111000,
B11111000,B11111000,B01111000,B00111000,B00011000,B00001000,B00000000,B00000000};
;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
attachInterrupt(0, button0ISR, RISING);
attachInterrupt(1, button1ISR, RISING);
interrupts();
/* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
/* Set the brightness to a medium values */
/* and clear the display */
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
lc.shutdown(1,false);
lc.setIntensity(1,8);
lc.clearDisplay(1);
lc.shutdown(2,false);
lc.setIntensity(2,8);
lc.clearDisplay(2);
lc.shutdown(3,false);
lc.setIntensity(3,8);
lc.clearDisplay(3);
ledState = 0;
breakLoopFlag = false;
Serial.print("ledState= ");
Serial.println(ledState);
Serial.print("breakLoopFlag= ");
Serial.println(breakLoopFlag);
}
//****************************SUPPORT METHODS***************************************
//
/*
This method updates the currentLED global variable to reflect the current state of the LEDs.
It takes an array as a parameter.
*/
void updateCurrentLED(byte newLED[]){
for(int i=0; i<sizeof(newLED); i++) {
currentLED[i]= newLED[i];
}
}
/*
This method will create a delay() in seconds for whatever number is passed to it.
*/
void delaySeconds(double seconds) {
seconds=seconds*1000;
delay(seconds);
}
/*
This method writes a single image to the LEDs
*/
void writeImage(byte image[], int sizeOfArray){
int addr = 0;
int row = 0;
for(int i=0; i<sizeOfArray; i++){
if(row==8){
row=0;
addr++;
}
lc.setRow(addr,row,image[i]);
row++;
}
updateCurrentLED(image);
}
//**************************************IMAGE METHODS**************************************
//
/*
This method turns all LEDs off.
*/
void clearScreen() {
writeImage(ClearScreen, sizeOfClearScreen);
}
/*
This method makes an upright :D face. Static image. This is also the default image for the LEDs.
*/
void smiley() {
while(!breakLoopFlag){
writeImage(Smiley, sizeOfSmiley);
}
breakLoopFlag = false;
}
/*
This method makes a heart. Static image.
*/
void heart() {
while(!breakLoopFlag){
writeImage(Heart1, sizeOfHearts);
delaySeconds(.5);
writeImage(Heart2, sizeOfHearts);
delaySeconds(.5);
}
breakLoopFlag = false;
}
//**************************************ISR METHODS****************************************
//
void button0ISR(){
ledState=1;
breakLoopFlag = true;
Serial.print("ledState= ");
Serial.println(ledState);
Serial.print("breakLoopFlag= ");
Serial.println(breakLoopFlag);
}
void button1ISR(){
ledState = 2;
breakLoopFlag = true;
Serial.print("ledState= ");
Serial.println(ledState);
Serial.print("breakLoopFlag= ");
Serial.println(breakLoopFlag);
}
void loop() {
switch(ledState) {
case 1:
smiley();
break;
case 2:
heart();
break;
default:
clearScreen();
}
}
Note: this is not my final sketch, just a test sketch for the time being. The reason why I have some of those helper methods in there is because I just copy and pasted the necessary ones from my main sketch. I had to implement some of them like that for various reasons (if you're curious and would like to see my main sketch too just let me know).
After playing with it a little bit, it looks like interrupt1 works fine the first time I press it, if it's the first interrupt I fire. Once I fire interrupt0, it does the weird thing were both ISRs fire no matter which interrupt I trigger. Again, there don't appear to be any shorts.