So I have three buttons attached to 19/21 and 21 (interrupts 4,3,2) and they are wired according to this schematic: (without the led)
http://www.dave-auld.net/index.php?option=com_content&view=article&id=107:arduino-interrupts&catid=53:arduino-input-output-basics&Itemid=107
I dont know what is going on, I have tried rising/falling/high/low but this code does not seem to display anything to my lcd when I presss the buttons. I took my multimeter to the pins of one of the buttons very lightly, and then that interupt text appeared. It was really odd.
i wonder if anyone can spot my mistake, because it seems like there's a poltergeist in the room...
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(52, 51, 50, 48, 49);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
int pbInLeft = 2; // Interrupt2 on pin 21
int pbInUse = 3; // Interrupt3 on pin 20
int pbInRight = 4;
void setup() {
display.begin();
display.setContrast(50);
attachInterrupt(pbInRight, Right, FALLING);
attachInterrupt(pbInUse, Use, FALLING);
attachInterrupt(pbInLeft, Left, FALLING);
// text display tests
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(BLACK);
display.print("0x");
display.println(0xDEADBEEF, HEX);
//display.display();
delay(2000);
}
void loop() {
int value = analogRead(15);
display.clearDisplay();
display.setCursor(0,0);
display.println(value);
display.display();
delay(10);
}
void Right()
{
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 > 100)
{
display.clearDisplay();
display.setCursor(0,0);
display.println("Right");
display.display();
delay(1000);
}
last_interrupt_time = interrupt_time;
}
void Left()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 100ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 100)
{
display.clearDisplay();
display.setCursor(0,0);
display.println("left");
display.display();
delay(1000);
}
last_interrupt_time = interrupt_time;
}
void Use()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 100ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 100)
{
display.clearDisplay();
display.setCursor(0,0);
display.println("Use");
display.display();
delay(1000);
}
last_interrupt_time = interrupt_time;
}
[/code
sorry its long, theres not much there though!