Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## randomglow.py (by Cyrox @ngb.to)
- ## Last edited: 29/06/2014
- ## -----------------------------
- ## Lights up random LEDs of the PiGlow (http://shop.pimoroni.com/products/piglow)
- ## Needs "PyGlow" python module (https://github.com/benleb/PyGlow/blob/master/pyglow.py)
- ##
- ##
- ## Usage:
- ##
- ## RandomGlow.py [[<MinimumBrightness>] [<MaximumBrightness>] [<UpdateRate>] [<ResetLEDs>]]
- ##
- ## <MinimumBrightness> - Value between 0 and 255 (default: 1)
- ## <MaximumBrightness> - Value between 1 and 255, can't be less than <MinimumBrightness> (default: 150)
- ## <UpdateRate> - Defines how fast the LEDs are switched in seconds (default: 0.05)
- ## <ResetLEDs> - True or False, if true, the LED will go off after each turn (default: True)
- from pyglow import PyGlow
- from time import sleep
- import random
- import sys
- ### DEFAULT SETTINGS ###
- rndMinBnDef = 1
- rndMaxBnDef = 155
- updateRateDef = 0.05
- resetLEDsDef = True
- ########################
- rndMinBn = rndMinBnDef
- rndMaxBn = rndMaxBnDef
- updateRate = updateRateDef
- resetLEDs = resetLEDsDef
- if len(sys.argv) >= 2 and 0 <= int(sys.argv[1]) <= 255:
- rndMinBn = int(sys.argv[1])
- if len(sys.argv) >= 3 and 1 <= int(sys.argv[2]) <= 255:
- rndMaxBn = int(sys.argv[2])
- if rndMinBn > rndMaxBn:
- rndMinBn = rndMinBnDef
- rndMaxBn = rndMaxBnDef
- if len(sys.argv) >= 4:
- try:
- updateRate = float(sys.argv[3])
- except ValueError:
- pass
- if len(sys.argv) >= 5:
- resetLEDs = (sys.argv[4].lower() != 'false')
- print "All arguments:", str(sys.argv)
- print "Minimum Brightness:", rndMinBn
- print "Maxmimum Brightness:", rndMaxBn
- print "Update rate (in secs):", updateRate
- print "Reset LEDs:", resetLEDs
- print "[PRESS CTRL+C TO EXIT]"
- pyglow = PyGlow()
- try:
- while True:
- rndLed = random.randint(1, 18)
- rndBn = random.randint(rndMinBn, rndMaxBn)
- pyglow.led(rndLed, rndBn)
- sleep(updateRate)
- if resetLEDs:
- pyglow.all(0)
- except KeyboardInterrupt:
- pyglow.all(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement