Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with sleep mode and reset #153

Open
Bogdan2282 opened this issue Sep 16, 2023 · 1 comment
Open

Help with sleep mode and reset #153

Bogdan2282 opened this issue Sep 16, 2023 · 1 comment

Comments

@Bogdan2282
Copy link

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); 
}
@Bogdan2282 Bogdan2282 changed the title Sleep mode and reset Help with sleep mode and reset Sep 18, 2023
@radiantwave
Copy link

Have you ever solved this? Your code looks a little weird to me.
If you still would like help, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants