/*
AudioDiWhy Wokwi #questions — 12/23 at 6:21 PM
An update, after screwing around with this more,
I am finding all variables that I put in the sketch reset,
not just volatile one. It seems like the sketch is crashing
the sim and then it starts again.
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"
*****Depends on Bounce being unckecked*****
*/
#include <TinyDebug.h>
// not needed in wokwi
#include <avr/io.h>
#include <avr/interrupt.h>
#define INT0_VECTOR INT0_vect
const int BTN_PIN = PB2;
const int LED_PIN = PB0;
volatile int value = 0;
int oldValue = 0;
void setup()
{
Debug.begin();
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
cli(); // Disable interrupts during setup
GIMSK = 0b01000000; // 9.3.2 GIMSK – General Interrupt Mask Register
//GIFR = 0b01000000; // 9.3.3 GIFR – General Interrupt Flag Register
//PCMSK = 0b00000000; // 9.3.4 PCMSK – Pin Change Mask Register
MCUCR = 0b00000010; // Table 9-2. Interrupt 0 Sense Control, falling
sei(); // enables interrupts
Debug.println("Ready\n");
}
void loop()
{
if (value != oldValue) {
oldValue = value;
Debug.println(value);
digitalWrite(LED_PIN, value % 2);
}
}
ISR(INT0_VECTOR)
{
value++; // Increment volatile variable
}