Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time, sys, os
- #import RPi.GPIO as GPIO
- SLEEP_TIME=1
- LED_INC=10
- TOP=80
- INC_OFF=0
- #GPIO.setmode(GPIO.BOARD)
- class LED:
- def __init__(self, name, pin, brightness):
- self.__name = name
- self.brightness = brightness
- self.__forward = True
- # Setup port
- #GPIO.setup(pin, GPIO.OUT)
- #self.__pwm = GPIO.PWN(pin, 1000)
- #self.__pwm.start(brightness)
- self.__inc_off_count = INC_OFF
- def inc(self):
- if self.brightness == 0:
- if self.__inc_off_count == INC_OFF:
- self.__inc_off_count = 0
- else:
- self.__inc_off_count+=1
- return
- if self.__forward:
- self.brightness+=LED_INC
- else:
- self.brightness-=LED_INC
- if self.brightness > 80:
- self.__forward = False
- self.brightness-=(LED_INC * 2)
- elif self.brightness < 0:
- self.__forward = True
- self.brightness+=(LED_INC * 2)
- self.update_led()
- #self.__pwn.ChangeDutyCycle(self.brightness)
- def update_led(self):
- if self.brightness <= 20:
- sys.stdout.write("\033[0;30m")
- elif self.brightness <= 40:
- sys.stdout.write("\033[1;30m")
- elif self.brightness <= 60:
- sys.stdout.write("\033[0;37m")
- else:
- sys.stdout.write("\033[1;37m")
- sys.stdout.write("*")
- #print ("LED %s %s" % (self.__name, self.brightness))
- def reverse(self):
- self.__forward = not self.__forward
- leds = [
- LED("1", 1, 80),
- LED("2", 2, 70),
- LED("3", 1, 60),
- LED("4", 1, 50),
- LED("5", 1, 40),
- LED("6", 1, 30),
- LED("7", 1, 20),
- LED("8", 1, 10),
- LED("9", 1, 0)
- ]
- while (True):
- clear = lambda: os.system('clear')
- clear()
- for led in leds:
- led.inc()
- sys.stdout.flush()
- if leds[-1].brightness == TOP or leds[0].brightness == TOP:
- for led in leds:
- led.reverse()
- time.sleep(SLEEP_TIME)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement