daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2018 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import time, sys, os
  3. #import RPi.GPIO as GPIO
  4.  
  5. SLEEP_TIME=1
  6. LED_INC=10
  7. TOP=80
  8. INC_OFF=0
  9.  
  10. #GPIO.setmode(GPIO.BOARD)
  11.  
  12. class LED:
  13.     def __init__(self, name, pin, brightness):
  14.         self.__name = name
  15.         self.brightness = brightness
  16.         self.__forward = True
  17.  
  18.         # Setup port
  19.         #GPIO.setup(pin, GPIO.OUT)
  20.         #self.__pwm = GPIO.PWN(pin, 1000)
  21.         #self.__pwm.start(brightness)
  22.         self.__inc_off_count = INC_OFF
  23.  
  24.  
  25.     def inc(self):
  26.         if self.brightness == 0:
  27.  
  28.             if self.__inc_off_count == INC_OFF:
  29.                 self.__inc_off_count = 0
  30.             else:
  31.                 self.__inc_off_count+=1
  32.                 return
  33.  
  34.         if self.__forward:
  35.             self.brightness+=LED_INC
  36.         else:
  37.             self.brightness-=LED_INC  
  38.  
  39.         if self.brightness > 80:
  40.             self.__forward = False
  41.             self.brightness-=(LED_INC * 2)
  42.         elif self.brightness < 0:
  43.             self.__forward = True
  44.             self.brightness+=(LED_INC * 2)
  45.         self.update_led()
  46.         #self.__pwn.ChangeDutyCycle(self.brightness)
  47.  
  48.     def update_led(self):
  49.         if self.brightness <= 20:
  50.             sys.stdout.write("\033[0;30m")
  51.         elif self.brightness <= 40:
  52.              sys.stdout.write("\033[1;30m")
  53.         elif self.brightness <= 60:
  54.              sys.stdout.write("\033[0;37m")
  55.         else:
  56.             sys.stdout.write("\033[1;37m")
  57.    
  58.  
  59.         sys.stdout.write("*")
  60.  
  61.         #print ("LED %s %s" % (self.__name, self.brightness))
  62.  
  63.     def reverse(self):
  64.         self.__forward = not self.__forward
  65.  
  66.  
  67. leds = [
  68. LED("1", 1, 80),
  69. LED("2", 2, 70),
  70. LED("3", 1, 60),
  71. LED("4", 1, 50),
  72. LED("5", 1, 40),
  73. LED("6", 1, 30),
  74. LED("7", 1, 20),
  75. LED("8", 1, 10),
  76. LED("9", 1, 0)
  77. ]
  78.  
  79. while (True):
  80.     clear = lambda: os.system('clear')
  81.     clear()
  82.     for led in leds:
  83.         led.inc()
  84.  
  85.     sys.stdout.flush()
  86.     if leds[-1].brightness == TOP or leds[0].brightness == TOP:
  87.         for led in leds:
  88.             led.reverse()
  89.  
  90.  
  91.  
  92.     time.sleep(SLEEP_TIME)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top