added pin change interupt for chaninging animation state
This commit is contained in:
parent
4f7736b055
commit
f2e601bc66
8 changed files with 131 additions and 56 deletions
35
button.ino
Normal file
35
button.ino
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue