-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
I wrote a sample code to sleep Attiny13 but I encountered a problem that even if I don't press the button Attiny13 reboots with 8sec intervals, it can be seen by the fact that the LED blinks every 8sec. Please help me to understand how to deep sleep correctly so that Attiny13 does not restart.And one more question why millis() does not work in this code, is it possible to use watchdog and millis(), if not, is there any alternative to millis(). Thanks in advance for your help (I am still a novice in this, and on the Internet could not find the necessary information).
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define ledPin 1
#define switchPin 4
boolean Switch;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
wdt_reset();
wdt_enable(WDTO_8S); // 15MS, 30MS, 60MS, 120MS, 250MS, 500MS, 1S, 2S, 4S, 8S
WDTCR |= _BV(WDCE);
sei();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
}
void loop() {
Switch = digitalRead(switchPin);
if(!Switch){
analogWrite(ledPin, 255);
}
else{
analogWrite(ledPin, 0);
sleep_enable();
sleep_cpu();
}
}
ISR (WDT_vect) {
WDTCR |= _BV(WDCE);
}
lazarevd
Metadata
Metadata
Assignees
Labels
No labels