Close

Display the minutes, please!

A project log for Abacus Clock

A clock that uses Abacus logic to display the current time.

Steven RochSteven Roch 05/13/2016 at 22:091 Comment

--FIRST UPDATE--

So after a bit of experimentation I finally came up with an unoptimized code to display the factors of 10 of the minutes.

Like I said, this is just for me to be sure everything will work like I imagined.

I took a picture of the testing-setup while it was displaying 23:3xh.

Today I will continue to get the second part of the minutes section to work.

Her you have my unoptimized code. Let's see what I can do to make it a bit shorter in the final product:

#!/usr/bin/python
# -*- coding: utf-8 -*-


# modules
import RPi.GPIO as GPIO
from time import strftime, sleep


# setup GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(6, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(26, GPIO.OUT)


# functions
def displayTime():
  minutes = strftime("%M")  
  row_3 = int(minutes)/10    
  row_4 = int(minutes)%10    
  if row_3 == 5:
    GPIO.output(5, True)
    GPIO.output(6, False)
    GPIO.output(13, False)
    GPIO.output(19, False)
    GPIO.output(26, False)
  elif row_3 == 4:
    GPIO.output(5, False)
    GPIO.output(6, True)
    GPIO.output(13, True)
    GPIO.output(19, True)
    GPIO.output(26, True)
  elif row_3 == 3:
    GPIO.output(5, False)
    GPIO.output(6, True)
    GPIO.output(13, True)
    GPIO.output(19, True)
    GPIO.output(26, False)
  elif row_3 == 2:
    GPIO.output(5, False)
    GPIO.output(6, True)
    GPIO.output(13, True)
    GPIO.output(19, False)
    GPIO.output(26, False)
  elif row_3 == 1:
    GPIO.output(5, False)
    GPIO.output(6, True)
    GPIO.output(13, False)
    GPIO.output(19, False)
    GPIO.output(26, False)
  else:
    GPIO.output(5, False)
    GPIO.output(6, False)
    GPIO.output(13, False)
    GPIO.output(19, False)
    GPIO.output(26, False)


# main program
def main():
  try:
    while True:
      sleep(0.1)
      displayTime()
  except KeyboardInterrupt:
    GPIO.cleanup()

if __name__ == "__main__":
  main()

I hope you have fun following the project! See you soon.

Discussions

Yann Guidon / YGDES wrote 05/13/2016 at 23:45 point

You could use a table/array, or a more compact coding technique :-)

  Are you sure? yes | no