Hello everyone! Forgive my poor skills, as I still try to educate myself in programming. I am trying to utilize an ATTINY85 with a push button switch (B3F-1000) to Start and Stop a looped program by putting the chip to Sleep and by Waking it up with the push of the same button. I am trying to integrate Nick Gammon's sketch from his website with my preexisting looped sketch, but in addition to butchering Nick's code, I am failing at successfully merging the two into one. I am getting an error with the ATTINY (that I would not get with a regular Arduino Uno); it says,
"Gammon_Sleep.cpp: In function 'void loop()':
Gammon_Sleep:42: error: 'BODS' was not declared in this scope
Gammon_Sleep:42: error: 'BODSE' was not declared in this scope"
Below, I'll post both scripts I'm trying to merge, in case someone is willing and able to provide some assistance.
int led = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(750); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
delay(750); // wait for a second
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(750); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
delay(750); // wait for a second
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(750); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
delay(2000); // wait for a second or two
}
#include <avr/sleep.h>
const byte LED = 9;
void wake ()
{
// cancel sleep as a precaution
sleep_disable();
// must do this as the pin will probably stay low for a while
detachInterrupt (0);
} // end of wake
void setup ()
{
digitalWrite (2, HIGH); // enable pull-up
} // end of setup
void loop ()
{
pinMode (LED, OUTPUT);
digitalWrite (LED, HIGH);
delay (50);
digitalWrite (LED, LOW);
delay (50);
pinMode (LED, INPUT);
// disable ADC
ADCSRA = 0;
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// Do not interrupt before we go to sleep, or the
// ISR will detach interrupts and we won't wake.
noInterrupts ();
// will be called when pin D2 goes low
attachInterrupt (0, wake, LOW);
// turn off brown-out enable in software
// BODS must be set to one and BODSE must be set to zero within four clock cycles
MCUCR = _BV (BODS) | _BV (BODSE);
// The BODS bit is automatically cleared after three clock cycles
MCUCR = _BV (BODS);
// We are guaranteed that the sleep_cpu call will be done
// as the processor executes the next instruction after
// interrupts are turned on.
interrupts (); // one cycle
sleep_cpu (); // one cycle
} // end of loop
Thanks in advance for any help; the camaraderie and support on this forum always amazes me.
-Michael