ATTiny85 and 3 pin change interrupts

Hi all

I'm using an ATTiny in a project and need to have 3 pushbutton inputs, each of which can wake up the sleeping Tiny, do a little work and go back to sleep. I've seen plenty of examples using just one switch, but I need 3 - and I thought the idea of using pin interrupts was for this type of issue, having a few inputs to take care of without polling. Apart from the pushbutton inputs, I have only one output so it may be that using a different approach is what's needed, but I'd be grateful for any assistance.

You can poll every one of the buttons to see which one was pressed during your pin change ISR, and run code accordingly. I would recommend using the port registers to poll the pins, as three digital reads will take some time (you always want an ISR to be as few clock cycles as possible!)


I haven't made that much progress with learning about the pin interrupts and polling each of them, as you suggest, any code would be great.


#include <avr/interrupt.h>
//Choose where your buttons are:
#define regist PCINT0_vect//All pins on Attiny85 :)

#define bttnA 0
#define bttnB 1
#define bttnC 2
ISR (regist){
    //A pressed!
  }else if(digitalRead(bttnB)){
    //B pressed!
  }else if(digitalRead(bttnC)){
    //C pressed!
void setup() {  
  //Are you using internal pullups? Uncomment these!
//  digitalWrite(bttnA,HIGH);
//  digitalWrite(bttnB,HIGH);
//  digitalWrite(bttnC,HIGH);
// enable interrupt for pins...
  GIMSK = 0b00100000;    // turns on pin change interrupts
  PCMSK = 0b00000111; //On pins 0,1,& 2
void loop() {
  // Nothing needed

This will use buttons on pins 0,1,& 2, listen for a change, and then run code accordingly!

Wow that was close timing, I was just writing a progress update. Thanks Fuzzyzilla. I now have this working using Reads for each pin in use, though my styling isn't quite as polished. It does work though, so now I wonder how much overhead can three reads possibly incur? This is for a remote control system and unless someone mashes the buttons i'd have thought it OK. I think researching registers for this might be helpful just for the sake of learning a bit more so may do that but this now works fine.