So, I thought I'd try using pin interrupts to make my code more performant. I used this helpful tutorial as a starting point: https://www.instructables.com/ATtiny85-Interrupt-Barebones-Example/
However, it uses PB1 for its input. That's no bueno for me. I need all three PWM outputs to drive an RGB LED, and PB1 is one of them. So, I switched the trigger pin to my usual go-to, PB3. Here's my code:
#include <avr/io.h>
#include <avr/interrupt.h>
#define INTERRUPT_PIN PCINT1
#define INT_PIN PB3
#define LED_PIN PB4
#define PCINT_VECTOR PCINT0_vect
void setup() {
pinMode(LED_PIN, OUTPUT);
cli();
PCMSK |= (1 << INTERRUPT_PIN);
GIMSK |= (1 << PCIE);
pinMode(INT_PIN, INPUT_PULLUP);
sei();
}
void loop() {}
ISR(PCINT_VECTOR) {
if (digitalRead(INT_PIN) == LOW) {
digitalWrite(LED_PIN, HIGH);
}else{
digitalWrite(LED_PIN, LOW);
}
}
And this works very well, thank you. I press the button, the LED lights up. Perfect, right? Right.
Except... the whole thing stops working and refuses to do anything if I set PB1 to an output, or even if I just plug the LED leg into it. I'm pretty sure my wiring is fine because it works nicely when I don't use interrupts. My first thoughts are, maybe it's expecting that pin to be an input too. Maybe I need different values for PCMSK or GIMSK or both. I tried a few, but nothing seems to work.
Is there a way for me to use PB3 as a pin interrupt, and all the remaining GPIO pins as outputs simultaneously?