Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example/interrupt #57

Merged
merged 3 commits into from
Aug 8, 2022
Merged

Example/interrupt #57

merged 3 commits into from
Aug 8, 2022

Conversation

jnuernberg
Copy link
Collaborator

Hi everyone,

After realising, that this library does not include an example, that uses interrupts, I created one.

I use alarm No. 1 of the DS3231 to trigger an interrupt every second and turn on and off the builtin LED of an Arduino.

This example could help on comments in issues #9 and #17.

Tested on:

  • Arduino UNO
  • Arduino nano

@IowaDave, would you mind reviewing the code? If you find nothing to complain about, we may push ahead and merge.

Cheers, Jacob

@jnuernberg jnuernberg added the example Specific examples and sample code label Aug 4, 2022
@IowaDave
Copy link
Collaborator

IowaDave commented Aug 4, 2022

This is good work. It will serve the purpose very nicely.

I see a few things to consider.

  1. Maybe change name of the RTC variable to "myRTC". The change would align with revisions to other examples made by Jefferson-Lopez back in March. See: his commit.
  2. Line 20, the comment identifies Alarm two as the target. Maybe should say Alarm one?
  3. Your note mentions turning an alarm on and off. The example code sends strings to Serial instead.
  4. What's the delay(100) for? if it's about playing nice with the alarm, maybe it would serve better inside the if block.

Thanks, David

@jnuernberg
Copy link
Collaborator Author

Thanks for the remarks. I took them into consideration and adjusted the code in the example. Clock is now myRTC and I corrected the comment referring to alarm two (now alarm one, as used).

But did you accidentally read the code in the first commit and not the latest version? I had started out with an example using serial communication to indicate alarm interrupts, but then switched to the builtin LED for then you can test without a serial monitor. The current example should not contain any write statements to Serial anymore.

The delay(100) in the loop is placed there to emulate other important code running and to slow down the loop. I changed the delay to 10 ms.

Best regards,
Jacob

@IowaDave
Copy link
Collaborator

IowaDave commented Aug 5, 2022 via email

@IowaDave
Copy link
Collaborator

IowaDave commented Aug 6, 2022

I figured out how to view the latest version. Take comfort from this: even old dogs (like me) can learn!

This one looks ready to go.

I concur that 10 ms is a reasonable amount of time to simulate other code running. Think about it. AVRs execute one machine code instruction per clock cycle. During 10 ms the CPU of an Arduino having a 16 MHz clock, like most of them do, would execute 16,000,000 instructions / 1000 mSEc * 10 mSec = 160,000 machine code instructions. Feels roomy to me!

@awickert
Copy link
Member

awickert commented Aug 8, 2022

Thanks to @jnuernberg for this and @IowaDave for reviewing. I have not used the square-wave (SQW) functionality of the DS3231 before, so also great to see this. Merging.

@awickert awickert merged commit 37c03a5 into master Aug 8, 2022
@jnuernberg jnuernberg deleted the example/interrupt branch August 14, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Specific examples and sample code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants