Hardware Reference
In-Depth Information
2.
There are several examples available from Adafruit in the WebIDE. Let's locate
the ex_7segment_clock.py example (in the IDE, it is located at Adafruit_
Raspberry-Pi-Python-Code | ex_7segment_clock.py ). This is a simple
example to display the current ime on the 7-segment backpack:
The ex_7segment_clock.py file location in the WebIDE
3.
Let's do a quick review of the program. We get started by imporing the datetime
and Adafruit_7Segment modules:
The segment variable is initialized as an instance of an I2C device at the
address 0x70. We enter an infinite loop and get the current time using the
datetime module:
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
Since the 7-segment LED backpack consists of four digits, we write the
current time at each position as follows along with a colon:
# Set hours
segment.writeDigit(0, int(hour / 10)) # Tens
segment.writeDigit(1, hour % 10) # Ones
# Set minutes
segment.writeDigit(3, int(minute / 10)) # Tens
segment.writeDigit(4, minute % 10) # Ones
 
Search WWH ::




Custom Search