7-Segment LED Backpack Clock with the Raspberry Pi

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Flossie
 
Posts: 2
Joined: Tue Jun 06, 2017 2:38 pm

7-Segment LED Backpack Clock with the Raspberry Pi

Post by Flossie »

Hi.

I am new to the programing scene and I am having problem with my project. I wanted to start out easy but I can not get some things to work. I am trying to make a raspberry pi clock with a 7-segment led backpack from adafruit and so far it works as intended except one thing, the brightness of the display. the display I able to have 1-15 different brightness levels. I am trying to add the brightness code but I can't get it to work. I have used google and searched in the forums but can't seem to get the hang of it. Hope you guys could help out. At the moment it is on full brightness and is a bit annoying when trying to sleep next to it. :(

Here is the CODE:

Code: Select all

#!/usr/bin/python

import time
import datetime

from Adafruit_LED_Backpack import SevenSegment

# Create display instance on default I2C address (0x70) and bus number.
display = SevenSegment.SevenSegment()

# Alternatively, create a display with a specific I2C address and/or bus.
# display = SevenSegment.SevenSegment(address=0x74, busnum=1)

# Initialize the display. Must be called once before using the display.
display.begin()

display.set_brightness(1)
# Keep track of the colon being turned on or off.
colon = False

# ===========================================================================
# Clock Example
# ===========================================================================
segment = SevenSegment.SevenSegment(address=0x70)

# Initialize the display. Must be called once before using the display.
segment.begin()

print "Press CTRL+Z to exit"

# Continually update the time on a 4 char, 7-segment display
while(True):
  now = datetime.datetime.now()
  hour = now.hour
  minute = now.minute
  second = now.second

  segment.clear()
  # Set hours
  segment.set_digit(0, int(hour / 10))     # Tens
  segment.set_digit(1, hour % 10)          # Ones
  # Set minutes
  segment.set_digit(2, int(minute / 10))   # Tens
  segment.set_digit(3, minute % 10)        # Ones
  # Toggle colon
  segment.set_colon(second % 2)              # Toggle colon at 1Hz

  # Write the display buffer to the hardware.  This must be called to
  # update the actual display LEDs.
  segment.write_display()

  # Wait a quarter second (less than 1 second to prevent colon blinking getting$
  time.sleep(0.25)
Best Regards

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: 7-Segment LED Backpack Clock with the Raspberry Pi

Post by jerryn »

you are initializing the display twice - once as "display", then again as "segment". But you are setting the brightness on "display" the using "segment" for the clock.
I think initializing "segment" resets the brightness to the default.
I think you just want to remove all the "display" references and add
segment.set_brightness(1)
after
segment.begin()
Last edited by jerryn on Tue Jun 06, 2017 3:45 pm, edited 1 time in total.

User avatar
Flossie
 
Posts: 2
Joined: Tue Jun 06, 2017 2:38 pm

Re: 7-Segment LED Backpack Clock with the Raspberry Pi

Post by Flossie »

Thanks a lot! That worked perfectly :)

Now it works with the brightness on the lowest setting. much more manageable :)

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: 7-Segment LED Backpack Clock with the Raspberry Pi

Post by jerryn »

Great! Glad it works!

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”