Skip to content

Commit

Permalink
final firmware commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amoghj98 committed Jul 7, 2019
1 parent fe7a346 commit e16aacc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
32 changes: 32 additions & 0 deletions examples/daily_alarm/daily_alarm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Example Arduino code to trigger an alarm at 1600hrs, i.e., at 4PM everyday.
*/
#include "ds3231.h"
#include <Wire.h>

#define interruptpin 2

class ds3231 rtc;
volatile byte flag=false;

void setup() {
Wire.begin();
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,false);
pinMode(interruptpin,INPUT_PULLUP); // Setup interrupt pin
digitalWrite(interruptpin,true);
attachInterrupt(digitalPinToInterrupt(interruptpin),isr_a1,FALLING); // setup interrupt
rtc.init();
rtc.set_alarm1(hr_min_sec_match,0x00,0x00,0x16); // Setup alarm 1 to trigger once everyday at the given time. (0x16 due to the use of 24 hr format)
rtc.arm_alarm1(); // arm alarm 1
}

void loop() {
digitalWrite(LED_BUILTIN,flag); // LED changing state indicates triggering of the alarm
rtc.clear_alarm1();
}

void isr_a1()
{
flag=!flag;
}
32 changes: 32 additions & 0 deletions examples/sq_wave_1s/sq_wave_1s.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Example Arduino code to generate a square wave of period 1s using interrupts
*/
#include "ds3231.h"
#include <Wire.h>

#define interruptpin 2

class ds3231 rtc;
volatile byte flag=false;

void setup() {
Wire.begin();
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,false);
pinMode(interruptpin,INPUT_PULLUP); // Setup interrupt pin
digitalWrite(interruptpin,true);
attachInterrupt(digitalPinToInterrupt(interruptpin),isr_a1,FALLING); // setup interrupt
rtc.init();
rtc.set_alarm1(every_second); // set alarm 1 to trigger once every second
rtc.arm_alarm1(); // arm alarm 1
}

void loop() {
digitalWrite(LED_BUILTIN,flag); // LED changing state indicates triggering of the interrupt
rtc.clear_alarm1();
}

void isr_a1()
{
flag=!flag;
}
14 changes: 7 additions & 7 deletions ds3231.cpp → src/ds3231.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ uint8_t ds3231::init()
//Wire.begin(); // ***NOTE: Uncomment this line if the RTC is the only I2C device in use. Else, call Wire.begin() in the setup function***
// ***NOTE: It is always advisable to intialise the I2C bus (by calling Wire.begin()) in the setup function***
write8(control,0x04);
set_year(0x19);
set_month(0x07);
set_date(0x02);
set_day(tuesday);
set_hours(0,0x20);
write8(minutes,0x59);
write8(seconds,0x55);
set_year(0x19); // Initialise year to 2019
set_month(0x07); // Initialise month to July
set_date(0x01); // Initialise date to 01
set_day(monday); // Initialise day of the week to Monday
set_hours(0,0x00); // Initialise hours to 00 (midnight)
write8(minutes,0x00); // Initialise minutes to 00
write8(seconds,0x00); // Initialise seconds to 00
return 0;
}

Expand Down
File renamed without changes.

0 comments on commit e16aacc

Please sign in to comment.