def spaz(): piglow = PyGlow() for x in range(1,19)+range(18,0,-1): piglow.set_leds([x], 255).update_leds() sleep(0.01) piglow.set_leds([x], 0).update_leds() sleep(0.05)
def main(): print(' %5s | %6s | %6s' % ('Hour', 'Minute', 'Second')) pg = PyGlow(brightness=150, pulse=True, speed=1000, pulse_dir=BOTH) try: while True: print_time(pg) except KeyboardInterrupt: print('') pg.all(0)
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) pyglow.led(1,100) sleep(1) pyglow.led(1,0) sleep(1) pyglow.update_leds()
if prev + 1 != i: write('\033[' + str(i / WIDTH + 1) + ';' + str(i % WIDTH + 1) + 'H') write(' ') def megabat(port): global Player0Megabats, Player0Height, Player1Megabats, Player1Height, Player0SizeCounter, Player1SizeCounter if port == 9 and Player0Megabats: Player0Height <<= 1 Player0Megabats -= 1 Player0SizeCounter = 0 elif port == 4 and Player1Megabats: Player1Height <<= 1 Player1Megabats -= 1 Player1SizeCounter = 0 glow = PyGlow() with Serial('/dev/ttyAMA0', 115200) as cereal: adc = SMBus(1) write = cereal.write write('\033[?25l') gpio.setwarnings(False) gpio.setmode(gpio.BCM) gpio.setup(4, gpio.IN, gpio.PUD_UP) gpio.setup(9, gpio.IN, gpio.PUD_UP) gpio.add_event_detect(4, gpio.FALLING, megabat, 15000) gpio.add_event_detect(9, gpio.FALLING, megabat, 15000) gpio.setup(10, gpio.IN, gpio.PUD_UP) gpio.setup(11, gpio.IN, gpio.PUD_UP) gpio.setup(17, gpio.OUT) gpio.setup(18, gpio.OUT)
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) pyglow.update_leds()
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) while True: pyglow.all(brightness=150, speed=60000, pulse=True) sleep(1) pyglow.update_leds()
# Description: # # This program lights up the indivdual colors like in # # Spiral Colors 3, but counter clockwise instead. # # Then the speeed gradually increases. Then the program starts # # over again. # # # # Requirements: PyGlow.py # # # # Author: Paul Ryan # # # ################################################################ from PyGlow import PyGlow from time import sleep pyglow = PyGlow() #Initialize pyglow.all(0) # Variables led_brightness = 100 # sleep_speed = 0.25 # Functions def red_leds_on(sleep_speed): sleep_speed = sleep_speed # Arm 1, Red pyglow.led(1, led_brightness)
##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * pulsetest.py - test the pulsing light feature # ##### from PyGlow import PyGlow b = input("Maximum brightness: ") s = input("Speed in milliseconds (try 1000 as a default): ") pyglow = PyGlow(brightness=b, speed=s, pulse=True) pyglow.all(0) print("Pulsing 1 Light") pyglow.led(1) print("Pulsing Arms") pyglow.arm(1) pyglow.arm(2) pyglow.arm(3) print("Pulsing All") pyglow.all()
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) while True: # blue > purple > red pyglow.color("blue", 100) pyglow.color("red", 0) sleep(0.1) pyglow.color("red", 10) pyglow.color("blue", 90) sleep(0.1) pyglow.color("red", 20) pyglow.color("blue", 80) sleep(0.1) pyglow.color("red", 30) pyglow.color("blue", 70) sleep(0.1) pyglow.color("red", 40) pyglow.color("blue", 60) sleep(0.1) pyglow.color("red", 50) pyglow.color("blue", 50) sleep(0.1) pyglow.color("red", 60) pyglow.color("blue", 40) sleep(0.1) pyglow.color("red", 70)
import pywapi import string from PyGlow import PyGlow from time import sleep import urllib pyglow = PyGlow() #Setup piglow and turn all off pyglow.all(0) yahoo_result = pywapi.get_weather_from_yahoo( 'FIXX0031' ) #get weather info from yahoo. Weather codes for city: https://www.edg3.uk/snippets/weather-location-codes/ condition = string.lower( yahoo_result['condition']['text'] ) #condition call. This gets a text readout of the current conditions if condition in ["partly cloudy", "mostly cloudy", "cloudy"]: pyglow.color("white", 150) elif condition in [ "mixed rain and snow", "mixed snow and sleet", "freezing drizzle", "freezing rain", "snow flurries", "light snow showers", "blowing snow", "snow", "hail", "sleet", "dust", "heavy snow", "scattered snow showers", "snow showers", "light snow", "light snow grains" ]: pyglow.color("yellow", 150) elif condition in [ "severe thunderstorms", "thunderstorms", "isolated thunderstorms", "scattered thunderstorms", "thundershowers"
from PyGlow import PyGlow from time import sleep myPiGlow = PyGlow() myPiGlow.all(0) while True: myPiGlow.color("white",90) sleep(1) myPiGlow.color("white",0) sleep(1) myPiGlow.color("blue",90) sleep(1) myPiGlow.color("blue",0) sleep(1) myPiGlow.color("green",90) sleep(1) myPiGlow.color("green",0) sleep(1) myPiGlow.color("yellow",90) sleep(1) myPiGlow.color("yellow",0) sleep(1) myPiGlow.color("orange",90) sleep(1) myPiGlow.color("orange",0) sleep(1) myPiGlow.color("red",90) sleep(1) myPiGlow.color("red",0)
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() count = 0 while (count < 8): pyglow.color("white", 100) sleep(0.05) pyglow.color("blue", 110) sleep(0.05) pyglow.color("green", 100) sleep(0.05) pyglow.color("yellow", 100) pyglow.color("white", 80) sleep(0.05) pyglow.color("orange", 100) pyglow.color("white", 60) sleep(0.05) pyglow.color("red", 100) pyglow.color("white", 40) sleep(0.05) pyglow.color("white", 0) sleep(0.05) pyglow.color("blue", 0) sleep(0.05) pyglow.color("green", 0) sleep(0.05) pyglow.color("yellow", 0) sleep(0.05) pyglow.color("orange", 0)
def pyglow_flash(): pyglow = PyGlow() val = 200 glowtime = 0.1 pyglow.color('white', val) sleep(glowtime) pyglow.color('blue', val) sleep(glowtime) pyglow.color('green', val) sleep(glowtime) pyglow.color('yellow', val) sleep(glowtime) pyglow.color('orange', val) sleep(glowtime) pyglow.color('red', val) sleep(glowtime) pyglow.color('white', 0) pyglow.color('blue', 0) pyglow.color('green', 0) pyglow.color('yellow', 0) pyglow.color('orange', 0) pyglow.color('red', 0)
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) count = 0 while (count < 20): pyglow.led(1, 100) pyglow.led(8, 100) pyglow.led(15,100) pyglow.led(4, 100) pyglow.led(11,110) pyglow.led(18,40) sleep(0.1) pyglow.led(1, 0) pyglow.led(8, 0) pyglow.led(15,0) pyglow.led(4, 0) pyglow.led(11,0) pyglow.led(18,0) pyglow.led(13,100) pyglow.led(2, 100) pyglow.led(9, 100) pyglow.led(16,100) pyglow.led(5, 110) pyglow.led(12,40) sleep(0.1) pyglow.led(13,0)
# PyGlow # ##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * pulsetest.py - test the pulsing light feature # ##### from PyGlow import PyGlow b = input("Maximum brightness: ") s = input("Speed in milliseconds (try 1000 as a default): ") pyglow = PyGlow(brightness=int(b), speed=int(s), pulse=True) pyglow.all(0) print("Pulsing 1 Light") pyglow.led(1) print("Pulsing Arms") pyglow.arm(1) pyglow.arm(2) pyglow.arm(3) print("Pulsing All") pyglow.all()
from bs4 import BeautifulSoup import urllib2 import re from PyGlow import PyGlow pyglow = PyGlow() pyglow.all(0) url="http://www.aurora-service.eu/aurora-forecast/" page=urllib2.urlopen(url) soup = BeautifulSoup(page.read()) kp = find_string = soup.body.findAll(text=re.compile('Kp'), limit=2) #rank = soup.find("div", {"class": "rank-box"}).h6.contents kpstring = str(kp) kpstring = kpstring[34:] kpstring = kpstring[:5] kpvalue = float(kpstring) print kpvalue if kpvalue >=2: #pyglow.all(0) pyglow.color("green", 200) elif (kpvalue <2) and (kpvalue > 1): #pyglow.all(0) pyglow.color("red", 200) elif kpvalue <=1: pyglow.color("yellow", 200)
def main(): score1 = 0 score2 = 0 server = 1 won = 0 gameover = False effects_timer = 0 effects_count = 0 effects_colour = '' effect = False sound_timer = 0 start = True start_time = time.time() ## Graphics class screen = Screen(constants.WIDTH, constants.HEIGHT) player1 = Paddle(screen, 3, constants.HEIGHT/2-1, constants.PLAYER1_COLOUR) player2 = Paddle(screen, constants.WIDTH-4, constants.HEIGHT/2-1, constants.PLAYER2_COLOUR) net = Net(screen, constants.NET_COLOUR) ball = Ball(screen, 5, 20, constants.BALL_COLOUR) pyglow = PyGlow() led = Led(5) net.draw() screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) # Initial value ball.velocity = [10.0,10.0] #Roughly 8 seconds to cross screen? screen.draw_str(25, 20, 'START', constants.WHITE) screen.draw_str(25, 26, 'GAME!', constants.WHITE) Buzzer.startMusic() while (True): # Calculate time since last frame end_time = time.time() frame_time = end_time - start_time start_time = end_time # Pyglow effects if (effect): effects_timer += frame_time if (won == 0): if ((effects_timer)%0.4 > 0.2 and (effects_timer - frame_time)%0.4 <= 0.2): pyglow.all(0) effects_count += 1 elif ((effects_timer)%0.4 <= 0.2 and (effects_timer - frame_time)%0.4 > 0.2): pyglow.color(effects_colour, 150) if (effects_count >= 5): effect = False effects_count = 0 else: if (effects_timer < 0.2): pyglow.color('white', 150) elif (effects_timer < 0.4): pyglow.color('blue', 150) elif (effects_timer < 0.6): pyglow.color('green', 150) elif (effects_timer < 0.8): pyglow.color('yellow', 150) elif (effects_timer < 1.0): pyglow.color('orange', 150) elif (effects_timer < 1.2): pyglow.color('red', 150) elif (effects_timer < 1.4): pyglow.all(0) pyglow.color('white', 150) effects_timer = 0 sound_timer += frame_time if (sound_timer / 0.15 >= 1): Buzzer.stopSound() sound_timer = 0 # Noise reduction for ADC value1 = 0 value2 = 0 for i in range(20): value1 += read_adc(CHAN2) value2 += read_adc(CHAN3) value1 /= 20 value2 /= 20 # Button inputs if (won == 0): # Hardware debounce # Player1 Serve if (GPIO.input(10) == 1): if (start): start = False screen.draw_str(25, 20, 'START', constants.BACKGROUND_COLOUR) screen.draw_str(25, 26, 'GAME!', constants.BACKGROUND_COLOUR) net.draw() time.sleep(0.2) ball.served = True start_time = time.time()-0.01 continue if (server == 1): ball.served = True # Player1 Power up if (GPIO.input(9) == 1 and not start): player1.power_up() # Software debounce # Player2 Serve if (read_adc(CHAN4) < 100): if (server == 2): ball.served = True # Player2 Power up if (debounce(1, 11) and not start): player2.power_up() # Lose condition if (ball.x >= screen.width-1): score1 += 1 ball.served = False # Draw new score screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) pyglow.color('blue', 150) effects_timer = 0 effects_colour = 'blue' effect = True # Work out who's turn to serve if ((score1+score2)%10 >= 5): server = 2 ball.x = player2.x-1 ball.y = player2.y + player2.size[1]/2 ball.velocity = [-10, 10] else: ball.x = player1.x+1 ball.y = player1.y + player1.size[1]/2 ball.velocity = [10, 10] # Lose condition if (ball.x <= 1): score2 += 1 ball.served = False # Draw new score screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) pyglow.color('red', 150) effects_timer = 0 effects_colour = 'red' effect = True # Work out who's turn to serve if ((score1+score2)%10 >= 5): server = 2 ball.x = player2.x-1 ball.y = player2.y + player2.size[1]/2 ball.velocity = [-10, 10] else: ball.x = player1.x+1 ball.y = player1.y + player1.size[1]/2 ball.velocity = [10, 10] # Has someone won? if (score1 >= 10): won = 1 elif (score2 >= 10): won = 2 # Move player paddles player1.move(value1) player2.move(value2) # Update paddles; if powerup player1.update(frame_time) player2.update(frame_time) # Move ball with paddle if not served if (not ball.served): if (server == 1): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player1.y + player1.size[1] / 2 ball.x = player1.x + 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True if (server == 2): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player2.y + player2.size[1] / 2 ball.x = player2.x - 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True # Collision Detection if (ball.roundx == player1.x): # Random speed rx = random.randint(5,15) ry = random.randint(5,15) # Different trajectories, depending on where the paddle was hit if (ball.roundy >= player1.y and ball.roundy <= player1.y + player1.size[1]/3): ball.velocity[1] = -ry ball.velocity[0] = rx Buzzer.hitSound() if (ball.roundy >= player1.y + player1.size[1]/3 and ball.roundy <= player1.y + player1.size[1]/3*2): ball.velocity[1] = 0 ball.velocity[0] = rx Buzzer.hitSound() if (ball.roundy >= player1.y + player1.size[1]/3*2 and ball.roundy <= player1.y + player1.size[1]): ball.velocity[1] = ry ball.velocity[0] = rx Buzzer.hitSound() # Redraw paddle player1._moved = True if (ball.roundx == player2.x): rx = random.randint(5,15) ry = random.randint(5,15) if (ball.roundy >= player2.y and ball.roundy <= player2.y + player2.size[1]/3): ball.velocity[1] = -ry ball.velocity[0] = -rx Buzzer.hitSound() if (ball.roundy >= player2.y + player2.size[1]/3 and ball.roundy <= player2.y + player2.size[1]/3*2): ball.velocity[1] = 0 ball.velocity[0] = -rx Buzzer.hitSound() if (ball.roundy >= player2.y + player2.size[1]/3*2 and ball.roundy <= player2.y + player2.size[1]): ball.velocity[1] = ry ball.velocity[0] = -rx Buzzer.hitSound() # Redraw paddle player2._moved = True # Update ball's position ball.update(frame_time) led.update(ball.x) # Draw ball ball.draw() # Draw player paddles player1.draw() player2.draw() # Draw net and score if ball was over them if (ball. last_pos != [ball.roundx, ball.roundy]): net.spot_draw(ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) # Print winner once if (won > 0 and not gameover): screen.draw_str(17, 20, 'PLAYER ' + str(won), constants.WHITE) screen.draw_str(25, 26, 'WINS!', constants.WHITE) gameover = True
# PyGlow # ##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * test.py - set brightness for each color individually # ##### from PyGlow import PyGlow pyglow = PyGlow() val = input("White: ") pyglow.color("white", val) val = input("Blue: ") pyglow.color("blue", val) val = input("Green: ") pyglow.color("green", val) val = input("Yellow: ") pyglow.color("yellow", val) val = input("Orange: ") pyglow.color("orange", val)
################################################## ## Switch each colour on in sequence on and off ## ## ## ## Example by Jason - @Boeeerb ## ################################################## from PyGlow import PyGlow from time import sleep pyglow = PyGlow() val = 20 colour = 1 while True: if colour == 19: colour = 1 if val == 20: val = 0 else: val = 20 pyglow.led(colour, val) sleep(0.05) colour = colour + 1
# get <your API key> from http://www.wunderground.com/weather/api f = urllib2.urlopen('http://api.wunderground.com/api/<your API key>/geolookup/q/autoip.json') json_string = f.read() parsed_json = json.loads(json_string) zip = parsed_json['location']['zip'] f = urllib2.urlopen('http://api.wunderground.com/api/<your API key>/geolookup/conditions/q/%s.json' % (zip)) json_string = f.read() parsed_json = json.loads(json_string) location = parsed_json['location']['city'] temp_f = parsed_json['current_observation']['temp_f'] print "Current temperature in %s is: %s" % (location, temp_f) f.close() pyglow = PyGlow() #Setup piglow and turn all off pyglow.all(0) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) temperature=int(temp_f) if temperature < 0: pyglow.color("blue", 255) elif temperature < 10: pyglow.color("blue", 255) pyglow.color("green", 200) elif temperature < 20:
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) while True: pyglow.color("blue", 100) sleep(1) pyglow.color("blue", 0) pyglow.color("red", 100) sleep(1) pyglow.color("red", 0) pyglow.update_leds()
#! /usr/bin/local/python3 from PyGlow import PyGlow from time import sleep import random pyglow = PyGlow() pyglow.all(0) while True: randomLED = random.randint(1,18) randomBright = random.randint(0,100) pyglow.led(randomLED,randomBright) sleep(0.1) pyglow.led(randomLED,0) pyglow.all(0)
from PyGlow import PyGlow from time import sleep b = 100 s = 1000 pyglow = PyGlow(brightness=b, speed=s, pulse=True) pyglow.all(0) count = 0 while (count < 5): pyglow.all() count = count + 1 pyglow.all(0)
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) count = 0 while (count < 5): pyglow.color("white", 60) sleep(0.1) pyglow.color("white", 0) pyglow.color("blue", 100) sleep(0.1) pyglow.color("blue", 0) pyglow.color("green", 100) sleep(0.1) pyglow.color("green", 0) pyglow.color("yellow",100) sleep(0.1) pyglow.color("yellow", 0) pyglow.color("orange",100) sleep(0.1) pyglow.color("orange", 0) pyglow.color("red", 100) sleep(0.1) pyglow.color("white", 50) sleep(0.1) pyglow.color("white", 0) pyglow.color("blue", 100)
from PyGlow import PyGlow from time import sleep import os pyglow = PyGlow() pyglow.all(0) for x in range(0, 15): pyglow.color("green", brightness=255, speed=500, pulse=True) sleep(1) os.system("sudo python /home/pi/pyglow/tempglow.py") #os.system("sudo python /home/pi/pyglow/weatherpyglow.py") #Set either of these, depending on which type of pyglow lamp you want to reset to
# # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * clock.py - binary clock by Jason (@Boeeerb) & Remi (rparpa) # [https://github.com/Boeeerb/PiGlow] # ##### from PyGlow import PyGlow from time import sleep from datetime import datetime pyglow = PyGlow() ## # You can customise these settings: ## # Show 12 or 24hr clock - 0= 24hr, 1= 12hr show12hr = 0 # Set brightness of LED - 1-255 # (recommend 10-20, put 0 and you won't see it!) led_brightness = 50 # Choose how to flash change of hour - 1= white leds, 2= all flash hour_flash = 2 # arms arm_top = {i: 0 for i in range(1, 7)}
# # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * clock.py - binary clock by Jason (@Boeeerb) # [https://github.com/Boeeerb/PiGlow] # ##### from PyGlow import PyGlow from time import sleep from datetime import datetime pyglow = PyGlow() ## # You can customise these settings: ## # Show 12 or 24hr clock - 0= 24hr, 1= 12hr show12hr = 0 # Set brightness of LED - 1-255 # (recommend 10-20, put 0 and you won't see it!) ledbrightness = 50 # Choose how to flash change of hour - 1= white leds, 2= all flash hourflash = 1 # h= hour, m= minutes, s= seconds armtop = "s"
# ##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * clock.py - binary clock by Jason (@Boeeerb) & Remi (rparpa) # [https://github.com/Boeeerb/PiGlow] # ##### from PyGlow import PyGlow from time import sleep from datetime import datetime pyglow = PyGlow() ## # You can customise these settings: ## # Show 12 or 24hr clock - 0= 24hr, 1= 12hr show12hr = 0 # Set brightness of LED - 1-255 # (recommend 10-20, put 0 and you won't see it!) led_brightness = 50 # Choose how to flash change of hour - 1= white leds, 2= all flash hour_flash = 2 # arms arm_top = {i: 0 for i in range(1, 7)}
# ##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * set_leds.py - how to control a individual set of leds by Ben (@ben_leb) # ##### from PyGlow import PyGlow from time import sleep pyglow = PyGlow() try: while True: # Choose a set of leds leds = [1, 3, 5, 11, 13, 15] # Save them with the brightness you want pyglow.set_leds(leds, 50) # Wait to demonstrate... sleep(3) # Light up the leds! pyglow.update_leds() sleep(3) # Now we want to shut down the first set
time.sleep(0.25) # noinspection PyUnusedLocal def inbox_item_received(self, inbox_item): for led in range(18): if _buffer[led] > 1: if random.randint(0, 1) == 0: _buffer[led] = 255 else: _buffer[led] = 0 _write_all() _maxbright = 255 _piglow = PyGlow() _piglow.all(0) _buffer = {} for l in range(18): _buffer[l] = 0 _modes = itertools.cycle([ DotsMode(), FlashMode() ]) _mode = next(_modes) def lights(): _mode.lights()
################################################## ## Switch each colour on in sequence on and off ## ## ## ## Example by Jason - @Boeeerb ## ################################################## from PyGlow import PyGlow from time import sleep pyglow = PyGlow() val = 100 color = 2 dark = 1 pyglow.all(0) while True: if color == 7: break pyglow.led(color, val) pyglow.led(dark, 0) sleep(0.5) color = color + 1 dark = dark + 1 while True: a = color b = a + 6 pyglow.led(a, val)
from PyGlow import PyGlow from time import sleep #b = 100 #s = 200 pyglow = PyGlow() #pyglow = PyGlow(brightness=b, speed=s, pulse=True) pyglow.all(0) while True: # pyglow.led(1) pyglow.color("red", 100) pyglow.color("orange", 0) pyglow.color("yellow", 0) pyglow.color("green", 0) pyglow.color("blue", 0) pyglow.color("white", 0) sleep(0.1) pyglow.color("red", 0) pyglow.color("orange", 0) pyglow.color("yellow", 0) pyglow.color("green", 0) pyglow.color("blue", 0) pyglow.color("white", 0) sleep(0.1) pyglow.color("red", 100) pyglow.color("orange", 100) pyglow.color("yellow", 0) pyglow.color("green", 0)
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) ### Blink 2 #while True: # pyglow.color("red", 100) # sleep(1) # pyglow.color("red", 0) # pyglow.color("orange", 100) # sleep(1) # pyglow.color("orange", 0) ### Pulse All while True: pyglow.pulse_all(150, 500) sleep(1)
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) while True: pyglow.color("green", 0) pyglow.color("red", 100) pyglow.color("yellow", 100) sleep(1) pyglow.color("green", 100) pyglow.color("red", 0) pyglow.color("yellow", 100) sleep(1) pyglow.color("green", 100) pyglow.color("red", 100) pyglow.color("yellow", 0) sleep(1) pyglow.update_leds()
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) pyglow.led(1, 100) sleep(1) pyglow.led(1, 0) sleep(1) pyglow.update_leds()
##### # # Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * cpu.py - cpu percentage utilisation indicator by Jason (@Boeeerb) # [https://github.com/Boeeerb/PiGlow] # ! requires psutil - sudo apt-get install python-psutil # ##### from PyGlow import PyGlow from time import sleep import psutil pyglow = PyGlow() while True: cpu = psutil.cpu_percent() pyglow.all(0) if cpu < 5: pyglow.color("white", 20) elif cpu < 20: pyglow.color("white", 20) pyglow.color("blue", 20) elif cpu < 40: pyglow.color("white", 20) pyglow.color("blue", 20) pyglow.color("green", 20)
#PyGlow test from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) while True: pyglow.color("green", 0) pyglow.color("red", 100) pyglow.color("yellow",100) sleep(1) pyglow.color("green", 100) pyglow.color("red", 0) pyglow.color("yellow", 100) sleep(1) pyglow.color("green", 100) pyglow.color("red",100) pyglow.color("yellow", 0) sleep(1) pyglow.update_leds()
import pywapi import string from PyGlow import PyGlow from time import sleep import urllib pyglow = PyGlow() #Setup piglow and turn all off pyglow.all(0) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) pyglow.all(brightness=255, speed=500, pulse=True) sleep(1) yahoo_result = pywapi.get_weather_from_yahoo( 'FIXX0031' ) #This gets the weather from Yahoo. Set the code for your city: https://www.edg3.uk/snippets/weather-location-codes/ temp = yahoo_result['condition'][ 'temp'] # This gets only the temperature from the conditions print temp temperature = int(temp) if temperature < -20: pyglow.color("blue", 255) elif temperature < -10: pyglow.color("blue", 255) pyglow.color("green", 200) elif temperature < -5: pyglow.color("green", 255) pyglow.color("blue", 255) pyglow.color("orange", 150) pyglow.color("yellow", 255)
#first wing (1 of 3 wings), LEDs 1-6 FAN1 = range(1,7) #second wing (2 of 3 wings), LEDs 13-18 FAN2 = range(13,19) #third wing (3 of 3 wings), LEDs 7-12 FAN3 = range(7,13) #LED INDEXES GROUPED BY COLOR RED = [1, 7, 13] ORANGE = [2, 8, 14] YELLOW = [3, 9, 15] GREEN = [4, 10, 16] BLUE = [5, 11, 17] WHITE = [6, 12, 18] #reset the colors to zero brightness piglow = PyGlow() piglow.all(0) #functions def slow_pulse_piglow(color): piglow = PyGlow(brightness=PULSE_BRIGHTNESS, pulse=True, speed=5000, pulse_dir=BOTH) piglow.set_leds(color).update_leds() try: while True: #cycle through the colors with a slow pulse map(slow_pulse_piglow, [RED, ORANGE, YELLOW, GREEN, BLUE, WHITE]) except: piglow.all(0)
def main(): score1 = 9 score2 = 0 server = 1 won = 0 gameover = False effects_timer = 0 effects_count = 0 effects_colour = '' effect = False start = True start_time = time.time() ## Graphics class screen = Screen(constants.WIDTH, constants.HEIGHT) player1 = Paddle(screen, 3, constants.HEIGHT / 2 - 1, constants.PLAYER1_COLOUR) player2 = Paddle(screen, constants.WIDTH - 4, constants.HEIGHT / 2 - 1, constants.PLAYER2_COLOUR) net = Net(screen, constants.NET_COLOUR) ball = Ball(screen, 5, 20, constants.BALL_COLOUR) pyglow = PyGlow() led = Led(5) net.draw() screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) # Initial value ball.velocity = [10.0, 10.0] #Roughly 8 seconds to cross screen? screen.draw_str(25, 20, 'START', constants.WHITE) screen.draw_str(25, 26, 'GAME!', constants.WHITE) while (True): end_time = time.time() frame_time = end_time - start_time start_time = end_time if (effect): effects_timer += frame_time if ((effects_timer) % 0.4 > 0.2 and (effects_timer - frame_time) % 0.4 <= 0.2): pyglow.all(0) effects_count += 1 elif ((effects_timer) % 0.4 <= 0.2 and (effects_timer - frame_time) % 0.4 > 0.2): pyglow.color(effects_colour, 150) if (effects_count >= 5): effect = False effects_count = 0 #noise reduction value1 = 0 value2 = 0 for i in range(20): value1 += read_i2c(CHAN2) value2 += read_i2c(CHAN3) value1 /= 20 value2 /= 20 if (won == 0): # Hardware debounce # Player1 Serve if (GPIO.input(10) == 1): if (start): start = False screen.draw_str(25, 20, 'START', constants.BACKGROUND_COLOUR) screen.draw_str(25, 26, 'GAME!', constants.BACKGROUND_COLOUR) net.draw() if (server == 1): ball.served = True # Player1 Power up if (GPIO.input(9) == 1): player1.power_up() # Software debounce # Player2 Serve if (debounce(0, 17)): if (server == 2): ball.served = True # Player2 Power up if (debounce(1, 11)): player2.power_up() # Lose condition if (ball.x >= screen.width - 1): score1 += 1 ball.served = False screen.draw_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR) pyglow.color('blue', 150) effects_timer = 0 effects_colour = 'blue' effect = True if ((score1 + score2) % 10 >= 5): server = 2 ball.x = player2.x - 1 ball.y = player2.y + player2.size[1] / 2 ball.velocity = [-10, 10] else: ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 ball.velocity = [10, 10] if (ball.x <= 1): score2 += 1 ball.served = False ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 screen.draw_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR) pyglow.color('red', 150) effects_timer = 0 effects_colour = 'red' effect = True if ((score1 + score2) % 10 >= 5): server = 2 ball.x = player2.x - 1 ball.y = player2.y + player2.size[1] / 2 ball.velocity = [-10, 10] else: ball.x = player1.x + 1 ball.y = player1.y + player1.size[1] / 2 ball.velocity = [10, 10] if (score1 >= 10): won = 1 elif (score2 >= 10): won = 2 # TODO: Reduce noise; multiple reads before move? player1.move(value1) player2.move(value2) player1.update(frame_time) player2.update(frame_time) if (not ball.served): if (server == 1): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player1.y + player1.size[1] / 2 ball.x = player1.x + 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True if (server == 2): ball.last_pos = [ball.roundx, ball.roundy] ball.y = player2.y + player2.size[1] / 2 ball.x = player2.x - 1 ball.roundx = int(round(ball.x)) ball.roundy = int(round(ball.y)) if (ball.last_pos != [ball.roundx, ball.roundy]): ball._moved = True # Collision Detection if (ball.roundx == player1.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player1.y and ball.roundy <= player1.y + player1.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 and ball.roundy <= player1.y + player1.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = rx if (ball.roundy >= player1.y + player1.size[1] / 3 * 2 and ball.roundy <= player1.y + player1.size[1]): ball.velocity[1] = ry ball.velocity[0] = rx # Redraw paddle player1._moved = True if (ball.roundx == player2.x): rx = random.randint(5, 15) ry = random.randint(5, 15) if (ball.roundy >= player2.y and ball.roundy <= player2.y + player2.size[1] / 3): ball.velocity[1] = -ry ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 and ball.roundy <= player2.y + player2.size[1] / 3 * 2): ball.velocity[1] = 0 ball.velocity[0] = -rx if (ball.roundy >= player2.y + player2.size[1] / 3 * 2 and ball.roundy <= player2.y + player2.size[1]): ball.velocity[1] = ry ball.velocity[0] = -rx # Redraw paddle player2._moved = True ball.update(frame_time) led.update(ball.x) ball.draw() player1.draw() player2.draw() net.spot_draw(ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE1[0], constants.SCORE1[1], score1, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) screen.spot_num(constants.SCORE2[0], constants.SCORE2[1], score2, constants.SCORE_COLOUR, ball.last_pos[0], ball.last_pos[1]) if (won > 0 and not gameover): screen.draw_str(15, 20, 'PLAYER ' + str(won), constants.WHITE) screen.draw_str(25, 26, 'WINS!', constants.WHITE) gameover = True
def slow_pulse_piglow(color): piglow = PyGlow(brightness=PULSE_BRIGHTNESS, pulse=True, speed=5000, pulse_dir=BOTH) piglow.set_leds(color).update_leds()
# Python module to control Pimoronis PiGlow # [http://shop.pimoroni.com/products/piglow] # # * cpu.py - cpu percentage utilisation indicator by Jason (@Boeeerb) # [https://github.com/Boeeerb/PiGlow] # ! requires psutil - sudo apt-get install python-psutil # ##### from PyGlow import PyGlow from time import sleep import psutil pyglow = PyGlow() while True: cpu = psutil.cpu_percent() pyglow.all(0) if cpu < 5: pyglow.color("white", 20) elif cpu < 20: pyglow.color("white", 20) pyglow.color("blue", 20) elif cpu < 40: pyglow.color("white", 20) pyglow.color("blue", 20) pyglow.color("green", 20)
#! /usr/bin/python # newPiGlow.py # Author: Darrell Little # Version: 0.2 # Date: 03/04/2015 from PyGlow import PyGlow from time import sleep myPiGlow = PyGlow() colors = ["white","blue","green","yellow","orange","red"] c = 0 myPiGlow.all(0) print "Beginning Colors" while c < 5: for x in colors: print "Color: ",x myPiGlow.color(x,90) sleep(1) myPiGlow.color(x,0) sleep(1) c += 1 print "End Colors"
import RPi.GPIO as GPIO import config import logging import time import threading if config.enable_pyglow: from PyGlow import PyGlow pyglow = PyGlow(brightness=config.pyglow_default_brightness) led_io_ports = [5, 6, 12, 13, 16, 19, 20, 26] current_led_showing = None def setup(): logging.info("leds: setup called.") GPIO.setmode(GPIO.BCM) #use Broadcom GPIO names for port in led_io_ports: GPIO.setup(port, GPIO.OUT, initial=0) def test(): # flash each led for 0.5 secs """ for port in led_io_ports: GPIO.output(port, 1) time.sleep(0.5) GPIO.output(port, 0) flash_pyglow() """ play_pyglow_effect()
from PyGlow import PyGlow from time import sleep import os pyglow = PyGlow() pyglow.all(0) for x in range(0, 15): pyglow.color("orange", brightness=255, speed=500, pulse=True) sleep(1) os.system("sudo python /home/pi/pyglow/tempglow.py") #os.system("sudo python /home/pi/pyglow/weatherpyglow.py") #Set either of these, depending on which type of pyglow lamp you want to reset to
from smbus import SMBus from time import sleep import RPi.GPIO as rpi import re import Tkinter from PyGlow import PyGlow pyglow = PyGlow() """ The PyGlow() object can accept four optional parameters: brightness=None - sets default brightness level (value: number from 0 and 255) speed=None - sets default pulsing speed in milliseconds (value: number > 0) pulse=None - enables pulsing by default (value: True or False) pulse_dir=None - sets default pulsation direction (value: UP, DOWN, BOTH) """ #
bat_size[1] = default_bat_size output( ANSIEscape.draw_bat(window_size[0] - 2, bat_position[1], bat_size[1])) # Test code to see whether we are running properly on the Pi or not, opens the serial connection if we are if not debug: # Open Pi serial port, speed 115200 bits per second serialPort = Serial("/dev/ttyAMA0", 115200) # Should not need, but just in case if not serialPort.isOpen(): serialPort.open() # Set up the PyGlow module pyglow = PyGlow() # Set up the RPi.GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # Enable the LEDs for the bat position for i in leds: GPIO.setup(i, GPIO.OUT) # Enable the pins for the serve and power-up buttons GPIO.setup(8, GPIO.IN) GPIO.setup(9, GPIO.IN) GPIO.setup(10, GPIO.IN) GPIO.setup(11, GPIO.IN)
################################################################ # Description: # # This program is basically my "Light the Fuse" program in # # reverse. It lights up 2 arms at once and converges into the # # third arm. # # # # Requirements: PyGlow.py # # # # Author: Paul Ryan # # # ################################################################ from PyGlow import PyGlow from time import sleep pyglow = PyGlow() # Initialize pyglow.all(0) # Functions def confluence_2_and_3_into_1(sleep_speed): ''' Uncomment the following line for feedback while the program is running ''' #print "Confluence 2 and 3 into 1..." # Arm 2 and 3, Red pyglow.led(7,120) pyglow.led(13,120) sleep(sleep_speed) # Arm 2 and 3, Orange pyglow.led(8,120) pyglow.led(14,120)
from PyGlow import PyGlow from time import sleep pyglow = PyGlow() pyglow.all(0) count = 0 while (count < 10): pyglow.led(1, 100) pyglow.led(7, 100) pyglow.led(13,100) sleep(0.1) pyglow.led(1, 0) pyglow.led(7, 0) pyglow.led(13,0) pyglow.led(2, 100) pyglow.led(8, 100) pyglow.led(14,100) sleep(0.1) pyglow.led(2, 0) pyglow.led(8, 0) pyglow.led(14,0) pyglow.led(3, 100) pyglow.led(9, 100) pyglow.led(15,100) sleep(0.1) pyglow.led(3, 0) pyglow.led(9, 0)