Created
March 3, 2019 08:17
-
-
Save Artur-/7cd802ae954345f0eefcfcc408de6a32 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/env python | |
# -*- coding: utf-8 -*- | |
import time | |
import tm1637 | |
import RPi.GPIO as IO | |
import threading | |
import pygame | |
Display = tm1637.TM1637(CLK=3, DIO=2, brightness=1.0) | |
IO.setup(4, IO.IN, IO.PUD_UP) | |
IO.setup(23, IO.OUT) | |
IO.output(23, False) | |
p = IO.PWM(23, 100) | |
def ledBrightness(): | |
while 1: | |
for i in range(3,100,3): | |
p.ChangeDutyCycle(i); | |
time.sleep(0.03) | |
for i in range(100,3,-3): | |
p.ChangeDutyCycle(i); | |
time.sleep(0.03) | |
pygame.mixer.init() | |
mikro = pygame.mixer.Sound("m.wav") | |
mikro.set_volume(1.0) | |
pling = pygame.mixer.Sound("pling.wav") | |
try: | |
ledThread = threading.Thread(target=ledBrightness) | |
ledThread.start() | |
while 1: | |
while IO.input(4): | |
time.sleep(0.01) | |
p.start(1) | |
mikro.play() | |
Display.SetBrightness(5.0 / 10.0) | |
Display.ShowDoublepoint(True) | |
for i in range(10,-1,-1): | |
Display.Show([0, 0, i/10, i%10]) | |
time.sleep(1) | |
mikro.stop() | |
pling.play() | |
Display.Clear() | |
p.stop() | |
IO.output(23, False) | |
except KeyboardInterrupt: | |
1 | |
finally: | |
Display.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment