Created
March 2, 2021 22:14
-
-
Save sk-t3ch/8b15d27dfe6d6447e26387bfec1a2d42 to your computer and use it in GitHub Desktop.
Smart Buoy - Control power with RTC module turns on every 15 seconds
This file contains 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 <DS3232RTC.h> | |
#include <Wire.h> | |
int led = LED_BUILTIN; | |
void setup() { | |
Serial.begin(115200); | |
Wire.begin(); | |
pinMode(led, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(led, HIGH); | |
delay(3000); | |
reset_alarm(); | |
} | |
void reset_alarm(){ | |
Wire.beginTransmission(0x70); | |
Wire.write(1 << 6); | |
Wire.endTransmission(); | |
RTC.alarmInterrupt(ALARM_1, true); // alarm is an output trigger | |
RTC.squareWave(SQWAVE_NONE); | |
// 0h 0m 0s | |
setTime(0, 0, 0, 1, 1, 1970); | |
RTC.set(now()); | |
// set new alarm | |
RTC.setAlarm(ALM1_MATCH_SECONDS, 15, 0, 0, 1); | |
// clear old alarm flag - turning off system | |
RTC.alarm(ALARM_1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment