Created
June 23, 2015 13:49
-
-
Save michaelsarduino/16687b839a435575ea6f to your computer and use it in GitHub Desktop.
Stand-by_Modus für den Arduino: Sketch 2 mit Watchdoginterrupt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/sleep.h> | |
#include <avr/power.h> | |
#include <avr/wdt.h> | |
#include <EEPROM.h> //nachladen der Bibliotheken | |
int status_led = 0; | |
void setup() { | |
wdt_enable(WDTO_8S); //starten des Watchdoginterrupts | |
pinMode(13, OUTPUT); //definieren von Pin 13 als OUTPUT | |
} | |
void loop() { | |
status_led = EEPROM.read(10); | |
status_led = !status_led; | |
EEPROM.write(10, status_led); //auslesen des Status des EEPROM, umdrehen des Werts und abspeichern des neuen Werts | |
digitalWrite(13, status_led); //schalten der LED | |
enterSleep(); //senden des Arduino in den Schlafmodus | |
} | |
void enterSleep(){ | |
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //auswaehlen des Modus | |
sleep_enable(); //start des Schlafens ermoeglichen | |
sleep_mode(); //Stand-by-Modus starten | |
//hier geht es nach Wtchdoginterrupt weiter | |
sleep_disable(); //deaktivieren des Stand-by-Modus | |
power_all_enable(); //reaktivieren aller Funktionen | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment