I have been trying to use the interrupt in the ATTiny, but so far I have had only partial success. The ATTiny is programmed with its internal oscillator @ 8 Mhz. Basically, I have a couple of sensors, a LED and an output to a transistor. The core I'm using is the arduino-tiny-0100-0017.zip
Here is the code I'm using:
#include <PinChangeInterrupt.h>
const int Sensor1 = 0;
const int YellowLED = 1;
const int LDR = 2;
const int BJT = 3;
const int Switch = 4;
void setup() {
pinMode(Sensor1, INPUT);
pinMode(YellowLED, OUTPUT);
pinMode(LDR, INPUT);
pinMode(Switch, INPUT);
pinMode(BJT, OUTPUT);
attachPcInterrupt(4,newlevel,FALLING);
}
//Main Program
void loop() {
//Chequear sensor de movimiento
if (digitalRead(Sensor1) == 1) {
darkness();
}
} //END OF LOOP
void darkness() {
int LDRValue = analogRead(LDR);
if (LDRValue < LDRlimit) {
turnon();
delay(1000);
turnoff();
}
}
void newlevel() {
digitalWrite(YellowLED,HIGH);
int LDRNewValue = analogRead(LDR);
digitalWrite(YellowLED,LOW);
}
void turnon() {
digitalWrite(YellowLED, HIGH)
}
void turnoff() {
digitalWrite(YellowLED, LOW)
}
I have also tried the following:
http://www.insidegadgets.com/2011/02/27/how-to-use-the-pin-change-interrupt-on-attiny85/
http://forum.arduino.cc/index.php?topic=51838.0#
But still can't make it work. Either the output (BJT) works only when I ground the pin 4 (Arduino Pins) or it doesn't affect the program at all, which is to set a new darkness level. I even had the problem that taking Sensor1 out of the circuit, the whole action of activating the interrupt by grounding the pin 4, made the output of the BJT go High, which of course shouldn't be. My assumption on some cases is that the Interrupt is acting as a clock or resetting the ATTiny. But I can't figure out why.
I found out I can't use the Reset pin (5) unless I have a High Power Programmer, afterwards, so I'm not using it. I also tried changing the register bits for Interrupts accoridng to the Datasheet and other comments from this forum, but still no luck. Any help is appreciated.