-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcal.py
More file actions
54 lines (46 loc) · 1.46 KB
/
cal.py
File metadata and controls
54 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import schedule
import time
import datetime
import os
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
def reduce_string(string):
"""
Cut the string down to at most five chars so it fits on the board
Parameters
----------
string : str
Part of the date to be sent to the board
Returns
-------
str
The sliced string with a newline character. Helpful on Arduino side
of things
"""
return string[:3] + "\n"
def job():
"""
Get the date and update the board with this info
Gathers the month, date, and day of the week. Updates the arduino sketch
in the case of any changes. Write date information to the arduino.
"""
# Clear the buffer on the serial port
ser.flush()
date = datetime.datetime.now()
num_day = reduce_string(date.strftime('%d'))
word_day = reduce_string(date.strftime('%A'))
month = reduce_string(date.strftime('%B'))
os.system('/home/pi/bin/arduino-cli compile --fqbn arduino:avr:mega /home/pi/Desktop/bored/calendar/')
time.sleep(10)
os.system('/home/pi/bin/arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega /home/pi/Desktop/bored/calendar/')
time.sleep(7)
ser.write(month)
time.sleep(1)
ser.write(num_day)
time.sleep(1)
ser.write(word_day)
job() # Do it now
schedule.every().day.at("00:01").do(job) # And then do it at the start of every hour
while True:
schedule.run_pending()
time.sleep(1)