Hier ist mein RTC ds3231 Programm
Es löst einen Alarm aus und weckt das Arduino und aktiviert wieder einen sleep . Ich hoffe jemand kann dieses Programm testen mit einer RTC ds3231.
Jetzt meine Frage Void wake() schreibt nach dem Befehl sleep_disable(); ''Hallo''. Ist es möglich auch Pins high zu schreiben statt nur Serial.print(" hallo");.
Funktioniert das?
#include <Wire.h>
#include <RTClibExtended.h>
#include <avr/sleep.h>
RTC_DS3231 RTC; //we are using the DS3231 RTC
const byte LED = 9;
int INTERRUPT_PIN = 2;
byte AlarmFlag = 0;
byte ledStatus = 1;
int aktivpin = 10;
int wasserzeit = 25;
void wake()
{
// cancel sleep as a precaution
sleep_disable();
Serial.print(" hallo");
detachInterrupt (0);
} // end of wake
void setup ()
{
Serial.begin (9600);
pinMode (2, INPUT);
pinMode (aktivpin, OUTPUT);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__)); //set RTC date and time to COMPILE time
//clear any pending alarms
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
RTC.armAlarm(2, false);
RTC.clearAlarm(2);
RTC.alarmInterrupt(2, false);
//Set SQW pin to OFF (in my case it was set by default to 1Hz)
//The output of the DS3231 INT pin is connected to this pin
//It must be connected to arduino D2 pin for wake-up
RTC.writeSqwPinMode(DS3231_OFF);
//Set alarm1 every day at 18:33
RTC.setAlarm(ALM1_MATCH_HOURS, 17, 10, 0); //set your wake-up time here
RTC.alarmInterrupt(1, true);
} // 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, HIGH);
EIFR = bit (INTF0); // clear flag for interrupt 0
// 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 = bit (BODS) | bit (BODSE);
// The BODS bit is automatically cleared after three clock cycles
MCUCR = bit (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