//https://docs.wokwi.com/parts/wokwi-attiny85 simulate ATTINY85 on wokwi
//https://wokwi.com/projects/317140124437578305 get interrupts working
// https://wokwi.com/projects/318885209198035539 debounce function.
// https://thewanderingengineer.com/2014/08/11/pin-change-interrupts-on-attiny85/ datasheet attiny85 ints.
//https://electronics.stackexchange.com/questions/264434/attiny85-interrupt-confusion "only PB2 on attiny85 can be used to trap edge changes"
#include <TinyDebug.h>
//#include <avr/io.h>
//#include <avr/interrupt.h>
#define clockin PB2 //use digital I/O pin PB1 (pin 6 of IC) for input
#define INT0_VECTOR INT0_vect
#define LED PB0
volatile byte x = 0;
byte oldx = 0;
const int debounceDelay = 10; // milliseconds to wait until button input stable *
void setup() {
pinMode(clockin, INPUT_PULLUP); // Set our interrupt pin as input with a pullup
pinMode(LED, OUTPUT); //PB0 is GPIO output
cli(); // Disable interrupts during setup
PCMSK = 0b00000100; //enable PB2/PCINT2 as our interrupt pin.
GIMSK = 0b01000000; // enable ext pin interrupts; enable pin changes to be treated as interrupts.
MCUCR = 0b00000010; // int rising fall only. In wiwok unclick "bounce"
sei();
Debug.begin();
//Debug.println("you are beginning the sketch");
}
void loop() {
//display value and light LED
if (x != oldx) {
oldx = x;
Debug.println(x);
digitalWrite(LED, x % 2);
if (x == 4) {
x = 0;
}
}
}
ISR(INT0_VECTOR) {
x++;
}