|
| 1 | +# SPDX-FileCopyrightText: 2022 Eva Herrada for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import time |
| 6 | + |
| 7 | +import board |
| 8 | +from adafruit_lc709203f import LC709203F |
| 9 | +import adafruit_pcf8523 |
| 10 | +from simpleio import tone |
| 11 | +import neopixel |
| 12 | + |
| 13 | +rtc = adafruit_pcf8523.PCF8523(board.I2C()) |
| 14 | +battery = LC709203F(board.I2C()) |
| 15 | +indicator = neopixel.NeoPixel(board.A1, 1) |
| 16 | + |
| 17 | +days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] |
| 18 | +sleep = { |
| 19 | + 0: (22, 50), |
| 20 | + 1: (22, 50), |
| 21 | + 2: (22, 50), |
| 22 | + 3: (22, 50), |
| 23 | + 4: (22, 50), |
| 24 | + 5: None, |
| 25 | + 6: None, |
| 26 | +} |
| 27 | +wake = { |
| 28 | + 0: (11, 30), |
| 29 | + 1: (9, 50), |
| 30 | + 2: (9, 50), |
| 31 | + 3: (9, 50), |
| 32 | + 4: (9, 50), |
| 33 | + 5: (9, 50), |
| 34 | + 6: (11, 30), |
| 35 | +} |
| 36 | + |
| 37 | +BPM = 160 |
| 38 | + |
| 39 | +ringtone = [ |
| 40 | + (330, 0.5), |
| 41 | + (294, 0.5), |
| 42 | + (185, 1), |
| 43 | + (208, 1), |
| 44 | + (277, 0.5), |
| 45 | + (247, 0.5), |
| 46 | + (147, 1), |
| 47 | + (165, 1), |
| 48 | + (247, 0.5), |
| 49 | + (220, 0.5), |
| 50 | + (139, 1), |
| 51 | + (165, 1), |
| 52 | + (220, 2), |
| 53 | +] |
| 54 | + |
| 55 | +SET_DATE = True |
| 56 | +if SET_DATE: |
| 57 | + # Make sure to set this to the current date and time before using |
| 58 | + YEAR = 2022 |
| 59 | + MONTH = 3 |
| 60 | + DAY = 10 |
| 61 | + HOUR = 22 |
| 62 | + MINUTE = 49 |
| 63 | + SEC = 55 |
| 64 | + WDAY = 0 # 0 Sunday, 1 Monday, etc. |
| 65 | + t = time.struct_time((YEAR, MONTH, DAY, HOUR, MINUTE, SEC, WDAY, -1, -1)) |
| 66 | + |
| 67 | + print("Setting time to:", t) # uncomment for debugging |
| 68 | + rtc.datetime = t |
| 69 | + print() |
| 70 | + |
| 71 | +while True: |
| 72 | + t = rtc.datetime |
| 73 | + bat = min(max(int(battery.cell_percent), 0), 100) |
| 74 | + |
| 75 | + g = int((bat / 100) * 255) |
| 76 | + r = int((1 - (bat / 100)) * 255) |
| 77 | + indicator.fill([r, g, 0]) |
| 78 | + |
| 79 | + print(f"The date is {days[t.tm_wday]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}") |
| 80 | + print(f"The time is {t.tm_hour}:{t.tm_min}:{t.tm_sec}") |
| 81 | + print(f"Battery: {bat}%") |
| 82 | + |
| 83 | + night = sleep[t.tm_wday] |
| 84 | + morning = wake[t.tm_wday] |
| 85 | + |
| 86 | + if night: |
| 87 | + if night[0] == t.tm_hour and night[1] == t.tm_min: |
| 88 | + for i in ringtone: |
| 89 | + print(i[0]) |
| 90 | + tone(board.A0, i[0], i[1] * (60 / BPM)) |
| 91 | + time.sleep(60) |
| 92 | + |
| 93 | + if morning: |
| 94 | + if morning[0] == t.tm_hour and morning[1] == t.tm_min: |
| 95 | + for i in ringtone: |
| 96 | + print(i[0]) |
| 97 | + tone(board.A0, i[0], i[1] * (60 / BPM)) |
| 98 | + time.sleep(60) |
| 99 | + |
| 100 | + time.sleep(1) |
0 commit comments