8000 Update i2c_bcd_alarm.py by mikeysklar · Pull Request #55 · adafruit/Adafruit_CircuitPython_Register · GitHub
[go: up one dir, main page]

Skip to content

Update i2c_bcd_alarm.py #55

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

Closed
wants to merge 1 commit into from

Conversation

mikeysklar
Copy link
Contributor

@b-blake requested and provided fixes for alarm2 on the DS3231. Changes were minimal and easy confirm function example of alarm2 test used. Before patch would result fail to set alarm2 for minute alerts and return status of None. After this PR minute alarm2 can be set and proper status is returned as minutely. Also corrected the order of hours minutes seconds which was jumped up (aesthetic request from Bruce).

test code used on RP2040 Metro + Stemma QT connected DS3231

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)

@mikeysklar mikeysklar closed this Sep 11, 2024
@mikeysklar mikeysklar deleted the alarm2-minutely branch September 11, 2024 18:43
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.

1 participant
0