Created
November 24, 2017 14:19
-
-
Save LelandSindt/53006850942c299b337937d6ef941b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import RPi.GPIO as GPIO | |
from datetime import datetime | |
import time | |
#https://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another | |
def translate(sensor_val, in_from, in_to, out_from, out_to): | |
out_range = out_to - out_from | |
in_range = in_to - in_from | |
in_val = sensor_val - in_from | |
val=(float(in_val)/in_range)*out_range | |
out_val = out_from+val | |
return out_val | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(23, GPIO.OUT) | |
hour = GPIO.PWM(23, 50) | |
hour.start(4) | |
GPIO.setup(18, GPIO.OUT) | |
minute = GPIO.PWM(18, 50) | |
minute.start(4) | |
GPIO.setup(25, GPIO.OUT) | |
second = GPIO.PWM(25, 50) | |
second.start(4) | |
GPIO.setup(24, GPIO.OUT) | |
ampm = GPIO.PWM(24, 50) | |
ampm.start(4) | |
while True: | |
hour.start(translate(int(datetime.now().strftime("%I")), 0, 12, 0, 7)) | |
minute.start(translate(int(datetime.now().strftime("%M")), 0, 60, 0, 7)) | |
second.start(translate(int(datetime.now().strftime("%-S")), 0, 60, 0, 7)) | |
if datetime.now().strftime("%p") == "PM": | |
ampm.start(11.5) | |
else: | |
ampm.start(0) | |
time.sleep(.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment