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

alarm2 changes #57

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Conversation

mikeysklar
Copy link
Contributor

ds3231:
minute support
status
frequency re-order

@b-blake provided code from issue #50

test script used:

import time
import board
import busio
import adafruit_ds3231

i2c = busio.I2C(board.SCL, board.SDA)
rtc = adafruit_ds3231.DS3231(i2c)

# Set Alarm1 to trigger every minute
rtc.alarm2 = (time.struct_time((0, 0, 0, 0, 0, 0, 0, 0, -1)), "minutely")

rtc.alarm2_interrupt = True

def compact(t):
    t = str(t)
    t = t.replace(",", "")
    t = t.replace("'", "")
    t = t.replace("(s", "")
    t = t.replace("(", " ")
    t = t.replace(")", " ")
    t = t.replace("  ", " ")
    t = t.split(' ')
    u = t[0]
    u = u.replace("_", " ")
    t[0] = u[2]
    for v in range(1, 12):
        w = t[v].replace("=", " ")
        w = w.split(' ')
        #print(v, w)
        if   v == 10: t[v-1] = w[0]
        elif v == 11: t[v-1] = w[0]
        else:         t[v-1] = w[1]
        #print(v, t[v])
    print("{0:04}/{1:02}/{2:02} {3:02}:{4:02}:{5:02} {6:} {7:} {8:} {9:} {10:}".format(int(t[0]), int(t[1]), int(t[2]), int(t[3]), int(t[4]), int(t[5]), int(t[6]), int(t[7]), int(t[8]), t[9], t[10]))
    return t
    pass

while True:
    if rtc.alarm2_status:
        print("Alarm triggered!")
        compact(rtc.alarm2)
        rtc.alarm2_status = False  # Clear the alarm status
    time.sleep(1)

ds3231:
minute support
status
frequency re-order
more obvious to add an additional else than to get cray cray and make the logic truly unreadable.
@mikeysklar
Copy link
Contributor Author

mikeysklar commented Sep 12, 2024

@FoamyGuy or @caternuson - would you like to see further testing? @b-blake and myself have confirmed the PR works on the DS3231. I can test on other RTCs.

Since @b-blake provided the code and requested this be added over a year ago maybe a release can be cut soon?

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you!

@tannewt tannewt merged commit a68d6aa into adafruit:main Sep 12, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 24, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x to 1.2.0 from 1.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADXL37x#7 from RoaCode/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_MIDI to 1.5.0 from 1.4.19:
  > Merge pull request adafruit/Adafruit_CircuitPython_MIDI#57 from matthewbadeau/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 1.1.0 from 1.0.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#71 from adafruit/doc
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#68 from adafruit/rp2350
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#70 from adafruit/fix-rotaryencoder-example

Updating https://github.com/adafruit/Adafruit_CircuitPython_Register to 1.10.0 from 1.9.18:
  > Merge pull request adafruit/Adafruit_CircuitPython_Register#57 from mikeysklar/ds3231-alarm2-minute-status

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants