I'm trying to use the ATTINY85 sleep mode, and have it wake up using the pin change interrupt. I'm using Nick Gammon's example code
// ATtiny85 sleep mode, wake on pin change interrupt demo
// Author: Nick Gammon
// Date: 12 October 2013
// ATMEL ATTINY 25/45/85 / ARDUINO
//
// +-\/-+
// Ain0 (D 5) PB5 1| |8 Vcc
// Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1
// GND 4| |5 PB0 (D 0) pwm0
// +----+
#include <avr/sleep.h> // Sleep Modes
#include <avr/power.h>
const byte LED = 3; // pin 2
const byte SWITCH = 4; // pin 3 / PCINT4
ISR (PCINT0_vect)
{
// do something interesting here
}
void setup ()
{
pinMode (LED, OUTPUT);
pinMode (SWITCH, INPUT);
digitalWrite (SWITCH, HIGH); // internal pull-up
// pin change interrupt (example for D4)
PCMSK |= bit (PCINT4); // want pin D4 / pin 3
GIFR |= bit (PCIF); // clear any outstanding interrupts
GIMSK |= bit (PCIE); // enable pin change interrupts
} // end of setup
void loop ()
{
digitalWrite (LED, HIGH);
delay (500);
digitalWrite (LED, LOW);
delay (500);
goToSleep ();
} // end of loop
void goToSleep ()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
ADCSRA = 0; // turn off ADC
power_all_disable (); // power off ADC, Timer 0 and 1, serial interface
sleep_enable();
sleep_cpu();
sleep_disable();
power_all_enable(); // power everything back on
} // end of goToSleep
This all works fine - when I take the switch pin low, it wakes up, flashes the LED, then goes back to sleep again. However, if the switch pin is held low, the ATTINY continues to draw current of about 0.15mA - I presume because current is flowing through the internal pullup resistor. I guess that normally you would just have a kind of push button switch so that a momentary press caused the ATTINY to wake up, and current was only drawn while the switch was pressed. But I want to be able to have the switch go low, and stay low after the ATTINY goes back into sleep mode, but without current then being drawn (and so it's woken up next time by the switch going high.) Is there a way of doing this?