def draw(window): h,w = window.getmaxyx() audio_sample_array = impulse.getSnapshot(True) i = 0 l = len(audio_sample_array) / 4 sum = 0 step = l / ((w - 10) / 5) for x in range(3, w - 5, 5): value = audio_sample_array[i] bar(window, x, 3, h - 6 , value) sum += value i += step leds = 8 - min(8, int(sum * 2)) wiringPy.digital_write_byte((0xFF * (2 ** leds)) & 0xFF)
#!/usr/bin/env python import wiringPy import time wiringPy.setup() for pin in range(0,8): wiringPy.pin_mode(pin, 1) wiringPy.digital_write_byte(255) print "whats your name?" name = raw_input() print "hello " + name doubles = [1,2,4,8,16,32,64,128] snooze = 0.1 while (True): for no in doubles: wiringPy.digital_write_byte(no) time.sleep(snooze) doubles.reverse() #for no in range (0,256): # wiringPy.digital_write_byte(no) # time.sleep(0.0625)
import time import pygame def play_sound(filename, delay=0): pygame.mixer.music.load(filename) pygame.mixer.music.play() time.sleep(delay) random.seed() pygame.init() wiringPy.setup() for pin in range(0,8): wiringPy.pin_mode(pin, 1) wiringPy.digital_write_byte(255) play_sound("sounds/yodel.mp3") name = raw_input("What is your name? ") print "hello " + name levels = { 'easy': 10, 'medium': 100, 'hard': 500 } game_type = raw_input("choose level: easy, medium or hard? ") max_number = levels[game_type] answer = random.randint(1, max_number) lights = [0,1,3,7,15,31,63,127,255] lives = 8 print "guess which number I am thinking of [between 1 and " + str(max_number) + "]"
#!/usr/bin/env python import time import wiringPy if wiringPy.setup() < 0: print "Failed to initialize wiringPi" exit(-1) print "Rasberry Pi - Board revision:", wiringPy.board_revision() wiringPy.pin_mode(1, 2) for bright in range(0, 1024): wiringPy.pwm_write(1, bright) time.sleep(0.001) for bright in range(1024, -1, -1): wiringPy.pwm_write(1, bright) time.sleep(0.001) for pin in range(0, 8): wiringPy.pin_mode(pin, 1) for i in range(0, 256): wiringPy.digital_write_byte(i) time.sleep(0.02) wiringPy.digital_write_byte(0)
#!/usr/bin/env python import time import wiringPy if wiringPy.setup() < 0: print "Failed to initialize wiringPi" exit(-1) print "Rasberry Pi - Board revision:" , wiringPy.board_revision() wiringPy.pin_mode(1, 2) for bright in range(0, 1024): wiringPy.pwm_write(1, bright) time.sleep(0.001) for bright in range(1024, -1, -1): wiringPy.pwm_write(1, bright) time.sleep(0.001) for pin in range(0, 8): wiringPy.pin_mode(pin, 1) for i in range(0, 256): wiringPy.digital_write_byte(i) time.sleep(0.02) wiringPy.digital_write_byte(0)