sketch DS1307

IDE gerelateerde berichten
Berichten: 23
Geregistreerd: 27 Nov 2016, 15:22

Re: sketch DS1307

Berichtdoor hansc » 13 Mei 2022, 12:14

Heb nog eens op de Arduino site gekeken, en heb nog wat ideeën op gedaan.
Bij de bibliotheken nog wat aanvulling gevonden, ga hier mee verder en hou jullie op de hoogte.
Een ieder nog bedankt voor het mee denken.

mvg Hans

Advertisement

Berichten: 23
Geregistreerd: 27 Nov 2016, 15:22

Re: sketch DS1307

Berichtdoor hansc » 29 Mei 2022, 14:01

Heren,
Zoals gezegd ik heb een andere invulling hieraan gegeven TimeAlarmExample.
Deze werkt zonder problemen. Zal de sketch toevoegen. Zonder de DS1307.

[code]
/*
* TimeAlarmExample.pde
*
* This example calls alarm functions at 8:30 am and at 5:45 pm (17:45)
* and simulates turning lights on at night and off in the morning
* A weekly timer is set for Saturdays at 8:30:30
*
* A timer is called every 15 seconds
* Another timer is called once only after 10 seconds
*
* At startup the time is set to Jan 1 2011 8:29 am
*/

// Questions? Ask them here:
// http://forum.arduino.cc/index.php?topic=66054.0

#include <TimeLib.h>
#include <TimeAlarms.h>

int AlarmRelay = 4 ;

AlarmId id;

void setup() {
Serial.begin(9600);
pinMode(AlarmRelay = 4, OUTPUT);
digitalWrite(AlarmRelay, LOW);
while (!Serial) ; // wait for Arduino Serial Monitor

setTime (20,47,0,18,5,22); // set time to Saturday 8:29:00am Jan 1 2011

// create the alarms, to trigger at specific times
Alarm.alarmRepeat(20,00,0, MorningAlarm); // 8:30am every day
Alarm.alarmRepeat(20,01,0, EveningAlarm); // 11:45pm every day
Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm); // 8:30:30 every Saturday

// create timers, to trigger relative to when they're created
Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
id = Alarm.timerRepeat(2, Repeats2); // timer for every 2 seconds
Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds
}

void loop() {
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

// functions to be called when an alarm triggers:
void MorningAlarm() {
Serial.println("Alarm: - relay on");
digitalWrite(AlarmRelay,HIGH);
Serial.println("DOOR OPEN");
}

void EveningAlarm() {
Serial.println("Alarm: - relay off");
digitalWrite(AlarmRelay,LOW);
Serial.println("DOOR closed");
}

void WeeklyAlarm() {
Serial.println("Alarm: - its Monday Morning");
}

void ExplicitAlarm() {
Serial.println("Alarm: - this triggers only at the given date and time");
}

void Repeats() {
Serial.println("15 second timer");
}

void Repeats2() {
Serial.println("2 second timer");
}

void OnceOnly() {
Serial.println("This timer only triggers once, stop the 2 second timer");
// use Alarm.free() to disable a timer and recycle its memory.
Alarm.free(id);
// optional, but safest to "forget" the ID after memory recycled
id = dtINVALID_ALARM_ID;
// you can also use Alarm.disable() to turn the timer off, but keep
// it in memory, to turn back on later with Alarm.enable().
}

void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}

Groet Hans

Vorige

Terug naar Arduino IDE

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 11 gasten