Skip to main content

Flip digit clock library

Project description

licencelatest version

FlipDigitClockPython

wiring

Description

This library has for goal to control the FlipDigit clock composed of 6 Small 7-segment displays by alfazeta with a Raspberry Pi.

The clock was designed to be used with Particle Electron. This library although is designed to control the clock with a Raspberry Pi which is more common and more accessible than the Particle.

Install

The module is available on pip:

pip install flipdigitclock

Requirement

If you install the library with pip, the required package are installed automatically. If you use the library from sources, the only library needed for this to work is RPi.GPIO. Basic installation can be made like so:

pip3 install RPi.GPIO

or by using the provided requirments.txt file:

pip3 install -r requirments.txt

Wiring

You will need to connect GPIOs of the Raspberry Pi to the Particle Electron Slot. The default wiring is the following:

wiring

This wiring can be change in the constructor of the FlipDigitClock object which is the following:

clock = FlipDigitClock(A_DIG = 25, B_DIG = 5, C_DIG = 6, SET_DIG_EN = 12, RES_DIG_EN = 13, A_SEG = 19, B_SEG = 16, C_SEG = 26, SET_SEG_EN = 20, RES_SEG_EN = 21)

How to use

At first you need to create a clock object like so:

from flipdigitclock import *

clock =  FlipDigitClock()

If you want to change the wiring, check the upper part about it.

Warning notice

The sequence and timing of GPIO toggling is really specific! If the code is stopped, it might stop the sequence in unwanted state that may destroy your clock!

There is a function that reset all the GPIOs of your clock in a safe state:

clock.reset_all()

This function is called every time needed in the code but also if it receive a SIGINT (ctrl+c) or SIGTSTP (ctrl+z). Be really carefull to not stop the code during digit manipulation and how the code is excited!

Drive segments

To drive digits and segment, there is two enum and two arrays already in the lib to help you:

class DigitNumber(Enum):
    SEMI_COLLON_2 = 7
    SEMI_COLLON_1 = 3
    DIGIT_1 = 5
    DIGIT_2 = 1
    DIGIT_3 = 6
    DIGIT_4 = 2
    DIGIT_5 = 4
    DIGIT_6 = 0

DIGITS = [DigitNumber.DIGIT_1.value, DigitNumber.DIGIT_2.value, DigitNumber.DIGIT_3.value, DigitNumber.DIGIT_4.value, DigitNumber.DIGIT_5.value, DigitNumber.DIGIT_6.value, DigitNumber.SEMI_COLLON_2.value, DigitNumber.SEMI_COLLON_4.value]

class SegmentName(Enum):
    A = 3
    B = 5
    C = 1
    D = 6
    E = 2
    F = 4
    G = 0
    COLLON = 7

SEGMENTS = [SegmentName.A.value, SegmentName.B.value, SegmentName.C.value, SegmentName.D.value, SegmentName.E.value, SegmentName.F.value, SegmentName.G.value, SegmentName.COLLON.value]

The naming of the segment follow this pattern:

And the numbering of the digit start with DIGIT_1 on the left to DIGIT_6 on the right with SEMI_COLLON_1 for the left dots and SEMI_COLLON_2 for the right ones.

Drive single segment

You can now drive single segment on specific digit like so:

clock =  FlipDigitClock()

clock.set_segment(DigitNumber.DIGIT_3.value, SegmentName.G.value)				# set G segment of digit 3
clock.reset_segment(DigitNumber.DIGIT_2.value, SegmentName.A.value)				# reset A segment of digit 2

clock.reset_segment(DigitNumber.SEMI_COLLON_2.value, SegmentName.COLLON.value) # same function for semi-collon

Drive digit

Drive all segment of digit

You can directly drive all the segment of a digit with an hex code. The code is going from a for the lsb to g for the msb

As example, a 0 is 0b111111 or 0x3F:

clock =  FlipDigitClock()

clock.set_segments(DigitNumber.DIGIT_3.value, 0x3F)				# set the digit 3 to 0x3f (0)

You can also use function do directly set a number to a digit, clear a digit, set numbers to all digit, and set the semi-collon dots:

clock =  FlipDigitClock()

clock.clear_digit(DigitNumber.DIGIT_1.value)	# clear digit 1		
clock.clear_digits(DigitNumber.DIGIT_1.value)	# clear all digit			

clock.set_number(DigitNumber.DIGIT_1.value, 7)	# set the digit 1 to 7

clock.set_multiple_digit_number(123456)				# set all the digit to 12 34 56
clock.set_multiple_digit_number(123456, True, True)	# set all the digit to 12:34:56

clock.set_dots(False,False)		# reset both semi-collon

More examples

Three examples are available in the examples folder:

  • segments_example.py : This example shows how to use the DIGITS and SEGMENTS array to create a simple animation on the clock
  • clock_example.pychronometer_example : A simple clock displaying current time with seconds precision
  • chronometer_example.py : A simple chronometer with hundredth of a second precision

License

Under MIT license. Please see License File for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

flipdigitclock-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file flipdigitclock-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flipdigitclock-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for flipdigitclock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbdf7c788a8ddd8b3f2a51f0a206cc413f8cb2584f524bf364a4be0a709cca55
MD5 9b09769dd509c091de300437f595dced
BLAKE2b-256 88b082b9f60ad10ec90dce0fe09ecb0b78e70c5d37aaca1ab9af4ac6a4ab2931

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page