コード例 #1
0
#!/usr/bin/python

from ABE_ExpanderPi import RTC
from ABE_helpers import ABEHelpers
import time
"""
================================================
ABElectronics Expander Pi |  Set Time Demo
Version 1.0 Created 21/08/2014

run with: python demo-rtcset_date.py
===============================================

This demo shows how to set the time on the Expander Pi real-time clock
and then read the current time at 1 second intervals
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
rtc = RTC(bus)  # create a new instance of the RTC class

# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2013-04-23T12:32:11")

while True:
    # read the date from the RTC in ISO 8601 format and print it to the screen
    print rtc.read_date()
    time.sleep(1)  # wait 1 second
コード例 #2
0
    # convert a double into an eight byte array
    buf = bytearray(struct.pack('d', val))
    x = [0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(0, 8):
        x[i] = buf[i]
    return x


def array_to_double(val):
    # convert an eight byte array into a double
    dval, = struct.unpack('d', bytearray(val))
    return (dval)


# create a new instance of the RTC class
rtc = RTC()

# number to be written to the RTC memory
value = 0.0005

# convert the number into an array of bytes
writearray = double_to_array(value)

# write the array to the RTC memory
rtc.write_memory(0x08, writearray)

# read eight bytes from the RTC memory into an array
read_array = rtc.read_memory(0x08, 8)

# combine the array values into an number and print it
print(array_to_double(read_array))