charlie-cube/button.ino

35 lines
921 B
C++

#include <avr/interrupt.h>
void initButton()
{
DDRC = 0x00; // all pins are inputs
PORTC = 0b00110000; // set PC4 & PC5 to INPUT_PULLUP
cli();
PCICR |= 0b00000010; // Enables Port C Pin Change Interrupts
PCMSK1 |= 0b00110000; // PCINT12 (pin 27) (PC4)
sei();
}
ISR(PCINT1_vect)
{
static unsigned long lastInterruptTime_A4 = 0;
static unsigned long lastInterruptTime_A5 = 0;
if(digitalRead(A4) == LOW){
unsigned long interruptTime_A4 = millis();
if(interruptTime_A4 - lastInterruptTime_A4 > 200) {
currentState = nextState(currentState);
animationTimer = 0;
}
lastInterruptTime_A4 = interruptTime_A4;
}
if(digitalRead(A5) == LOW){
unsigned long interruptTime_A5 = millis();
if(interruptTime_A5 - lastInterruptTime_A5 > 200) {
currentState = nextState(currentState);
animationTimer = 0;
}
lastInterruptTime_A5 = interruptTime_A5;
}
}