EasyManua.ls Logo

AZ-Delivery DS3231 - Page 30

AZ-Delivery DS3231
32 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
The function called write_all() has eight arguments and returns no
value. The arguments represent part of data for date and time. The values
for all arguments are integer numbers in the ranges:
Seconds: 0 - 59, Minutes: 0 - 59, Hours: 0 - 23 Day: 1 - 7 (day in week),
Date: 1 - 31, Month: 1 12, Year: 0 - 99
Save_as_24h: True/False (tested with only as True)
Next, a new function is created, called check(). The function has one
argument and returns a string value. It is used to add leading zero to the
single digit number. The argument represents the number which is then
checked if it is a single or double digit number. If the number is a single
digit, then the string value ‘0{}’.format(num) is returned. If the number
is not a double digit number then the string value str(num) is returned.
After that, the try-except block of code is created. In the try block of
code, the indefinite loop is created. In the indefinite loop the RTC data is
read, and displayed in the terminal. There are two ways to display data in
the terminal. The first is by using the function read_datetime() and the
second is by using the function read_str().
To stop the script press ‘CTRL + C’ on the keyboard. This is called the
keyboard interrupt. When the keyboard interrupt happens, the except
block of code is executed, displaying message Script end! in the
terminal.
- 28 -