Close

[Trinket sensing] Push-buttons (using interrupts)

A project log for Home automation - Trinket Sensing

tjTJ 06/08/2015 at 10:270 Comments

Hardware

PB1_SIGTrinket Pin 11
PB2_SIGTrinket Pin 12

Learn about arduino interrupts

http://playground.arduino.cc/Main/PinChangeInterrupt

Arduino Code

#define BUT_RIGHT 11
#define BUT_LEFT  12

void pciSetup(byte pin)
{
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}

ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{
 /* if (digitalRead(BUT_RIGHT) == LOW || digitalRead(BUT_LEFT) == LOW)
    display.refresh();*/
}

void setup(void) {
  pinMode(BUT_RIGHT, INPUT);
  pinMode(BUT_LEFT, INPUT);
/*
  digitalWrite(BUT_RIGHT,HIGH); // set pullup - not required - hardware pullup
  digitalWrite(BUT_LEFT,HIGH); // set pullup - not required - hardware pullup
*/
  pciSetup(BUT_RIGHT);
  pciSetup(BUT_LEFT);
}

Discussions