Interrupts on attiny85

Hi
I’ve wrote a sketch for a flashlight, and now I’m trying to port it from the arduino to an Attiny85. I’m using this tutorial: http://hlt.media.mit.edu/?p=1695

Programming the attiny works. (tested with the blink sketch)
But now my interrupt doesn’t work. I’m using interrupt 0 with the internal pull-up and according to the datasheet of the attiny85 int0 is on pin7

#include <avr/sleep.h>


byte ledpin=0;  //pinnen definieren
byte drukknop=0;
volatile boolean ledStatus;  //volatile gebruiken doordat deze moet aangesproken worden in de interrupt methode
byte aantalDrukken;
long timer1;  //variabele om aantal milliseconden weg te schrijven
long timer2;
//instellingen:

//pinksnelheid in milliseconden:
int pinksnelheid=500;
//debouncetijd in milliseconden:
int debounce=200;
//standbytijd
int standbytijd=1000;



void setup(){
  pinMode(drukknop,INPUT);  //inputs en outputs definieren
  digitalWrite(drukknop,HIGH); // interne pull-up aanzetten
  pinMode(ledpin,OUTPUT);
  ledStatus=false;      //led om te beginnen uitzetten
  aantalDrukken=0;      //beginnen 
  attachInterrupt(0,knop,FALLING);      //interrupt 0 (digital pin 2) koppelen aan de routine
//Serial.begin(9600);
}

void loop(){                          //Main loop die de status controleert en naargelang de led aan, uit of laat pinken
  if(aantalDrukken==0){
  digitalWrite(ledpin,LOW);
  standby();
}
if(aantalDrukken==1){
  digitalWrite(ledpin,HIGH);
}
if(aantalDrukken==2){
  pinken();                            //verwijst naar de pinkroutine  
}

}
void knop(){                            //interrupt routine om te zorgen voor de input van de drukknop
  delay(debounce);                           //debouncetijd van 200 milliseconden
  if(digitalRead(drukknop)==LOW){
  aantalDrukken++;
  if(aantalDrukken>=3)                  //aantalDrukken bevat het cijfer dat de modus aanduid: 0= uit, 1= aan, 2=pinken
  aantalDrukken=0;                      //aantalDrukken moet terug naar 0 gaan wanneer hij op 3 komt
  timer1=millis();
}
}

void pinken(){                            //code om te pinken zonder gebruik te maken van delay's
  if(millis()-timer1>pinksnelheid){              //Delay's zouden code stilleggen en de input verstoren. Of onregelmatig maken.
    ledStatus= !ledStatus;
  digitalWrite(ledpin,ledStatus);
  timer1=millis();
  }
}

void standby(){
  if(millis()-timer2>standbytijd){    
  //  Serial.println("powering down"); 
 delay(1000);   
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    
    sleep_mode();
    sleep_disable();
  //  Serial.println("waking up");
    timer2=0;
  }
}

What could I be doing wrong?

You seem to be using Pin 0 for both the ledpin and drukknop. If the interrupt is on physical pin 7 you probably want drukknop to be 2.

Also note that "attachInterrupt()" is not listed as supported on the page you reference.

According to the datasheet, you can use any pin for interrupting. And it is really simple to set it up (after reading it over and over many times). One thing to note though is that all pins configured to fire the interrupt will fire the same ISR (interrupt service routine) so you would need to check which pin changed in here to figure out what to do.

So first things first: add the following 3 lines of code to your setup() function:

   GIMSK = (1 << PCIE); //Enable Pin Change Interrupts 
   PCMSK = (1 << PCINT2); //Set Pin 2 to cause an interrupt. You can also enable it on multiple pins 
   sei();

Now write the ISR:

ISR (PCINT0_vect)       //the PCINT0_vect vector is used to identify the pin change interrupt.
{ 
    if (PINB & (1 << PCINT2)) {  // check if Pin2 is HIGH or not
	//Do something
    } else {
	//Do something else
    }
}

Remember to keep your ISR’s as short as possible, i.e. you can set flags in your ISR, and then do heavy processing in your main loop if you detect the flags are set, and clear them after they have been processed.

Hi, I was wondering how you completed the sketch for the flashlight with the interrupt. I am trying something similar but got stuck with the coding on PCINT3