def pattern9(): # candle shine like random_led = 0 for y in range(6): random_led += 2**y * random.randint(0,1) * random.randint(0,1) # each LED choosen by 25% random_time = random.randint(1,3) # time between 0.1 and 0.3s tree.leds_on_and_wait(ALL - random_led, float(random_time)/10) random_time = random.randint(1,15) #light time between 0.1 and 1.5s tree.leds_on_and_wait(ALL, float(random_time)/10)
L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Two ways of randomly illuminating LEDs (they do the # same thing but Way 1 is easier to understand whilst # Way 2 is a shorter piece of code). # Way 1 for i in range(100): # repeat 100 times random_led = random.randint(0, 6) if (random_led == 0): tree.leds_on_and_wait(L0, 0.2) # D0 on for 0.2s elif (random_led == 1): tree.leds_on_and_wait(L1, 0.2) # D1 on for 0.2s elif (random_led == 2): tree.leds_on_and_wait(L2, 0.2) # D2 on for 0.2s elif (random_led == 3): tree.leds_on_and_wait(L3, 0.2) # D3 on for 0.2s elif (random_led == 4): tree.leds_on_and_wait(L4, 0.2) # D4 on for 0.2s elif (random_led == 5): tree.leds_on_and_wait(L5, 0.2) # D5 on for 0.2s elif (random_led == 6): tree.leds_on_and_wait(L6, 0.2) # D6 on for 0.2s # Way 2 for i in range(100): # repeat 100 times random_led = random.randint(0, 6) tree.leds_on_and_wait(1 << random_led, 0.5) # randomly selected LED on for 0.2s tree.all_leds_off() # extinguish all LEDs
# Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: all LEDs illuminated except for one each time for i in range(3): # repeat 3 times tree.leds_on_and_wait(ALL-L0, 0.5) # all on except for LED 0 tree.leds_on_and_wait(ALL-L1, 0.5) # all on except for LED 1 tree.leds_on_and_wait(ALL-L2, 0.5) # etc. tree.leds_on_and_wait(ALL-L3, 0.5) tree.leds_on_and_wait(ALL-L4, 0.5) tree.leds_on_and_wait(ALL-L5, 0.5) tree.leds_on_and_wait(ALL-L6, 0.5) tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
L4 = 16 L5 = 32 L6 = 64 AMBER = 1 # LED 0 = amber RED = 128 # LED 0 = red GREEN = 256 # LED 0 = green NO_LEDS = 0 BOTTOM6 = 2+4+8+16+32+64 # the 6 standard red LEDs # note that we must tell setup() that we have a bicolour LED tree.setup() # you must always call setup() first! # All the red LEDs will be permanently illuminated and we rotate # between the various colours for the bicolour LED at the top. for i in range(7): # repeat 7 times tree.leds_on_and_wait(BOTTOM6, 0.8) # top LED off tree.leds_on_and_wait(BOTTOM6 + GREEN, 0.8) # top LED green tree.leds_on_and_wait(BOTTOM6 + RED, 0.8) # top LED red tree.leds_on_and_wait(BOTTOM6 + AMBER, 0.8) # top LED amber tree.leds_on_and_wait(NO_LEDS, 0.8) # all LEDs off tree.leds_on_and_wait(GREEN, 0.8) # top LED green tree.leds_on_and_wait(RED, 0.8) # top LED red tree.leds_on_and_wait(AMBER, 0.8) # top LED amber tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: flash each LED in turn x = 1 while x == 1: try: for i in range(2): tree.leds_on_and_wait(L0, 0.3) # LED 0 on for 0.3 seconds tree.leds_on_and_wait(L1, 0.3) # LED 1 on for 0.3 seconds tree.leds_on_and_wait(L2, 0.3) # etc. tree.leds_on_and_wait(L3, 0.3) tree.leds_on_and_wait(L4, 0.3) tree.leds_on_and_wait(L5, 0.3) tree.leds_on_and_wait(L6, 0.3) for i in range(2): tree.leds_on_and_wait(L4 + L5, 1) tree.leds_on_and_wait(L0 + L2, 1) tree.leds_on_and_wait(L3 + L6 + L1, 1) for i in range(3): tree.leds_on_and_wait(ALL, 0.8) tree.leds_on_and_wait(NO_LEDS, 0.8)
L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Two slightly different ways of flashing *all* LEDs on and off. # Way 1 for i in range(3): # repeat 3 times tree.leds_on_and_wait(ALL, 0.5) # all on for 0.5s tree.leds_on_and_wait(NO_LEDS, 0.5) # all off for 0.5s # Way 2 for i in range(3): # repeat 3 times tree.leds_on_and_wait(ALL, 0.5) # all on for 0.5s tree.all_leds_off() # extinguish all LEDs time.sleep(0.5) # wait for 0.5s tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
# Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: flash each LED in turn for i in range(5): # repeat 5 times tree.leds_on_and_wait(L0, 0.3) # LED 0 on for 0.3 seconds tree.leds_on_and_wait(L1, 0.3) # LED 1 on for 0.3 seconds tree.leds_on_and_wait(L2, 0.3) # etc. tree.leds_on_and_wait(L3, 0.3) tree.leds_on_and_wait(L4, 0.3) tree.leds_on_and_wait(L5, 0.3) tree.leds_on_and_wait(L6, 0.3) tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
import tree # Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 LEDS = [L6, L4, L3, L2, L1, L5] duration = 10 tree.setup() for i in range(10): duration -= 1 for led in LEDS: # Spirals LEDs tree.leds_on_and_wait(led + L0, 0.01 * duration) tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup()
def pattern2(): # 2 or 3 tree.leds_on_and_wait(L1+L4, 0.5) tree.leds_on_and_wait(L5+L3+L0, 0.5) tree.leds_on_and_wait(L2+L6, 0.5) tree.leds_on_and_wait(L5+L3+L0, 0.5)
def pattern1(): # ascending tree.leds_on_and_wait(L0, 0.5) tree.leds_on_and_wait(L1, 0.5) tree.leds_on_and_wait(L2, 0.5) tree.leds_on_and_wait(L3, 0.5) tree.leds_on_and_wait(L4, 0.5) tree.leds_on_and_wait(L5, 0.5) tree.leds_on_and_wait(L6, 0.5)
DELAY = 0.2 # Configure switch GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN) tree.setup() # you must always call setup() first! # Two ways of randomly illuminating LEDs (they do the # same thing but Way 1 is easier to understand whilst # Way 2 is a shorter piece of code). # Loop until switch is pressed while GPIO.input(25) == 0: random_led = random.randint(0, 6) if (random_led == 0): tree.leds_on_and_wait(L0, DELAY) # D0 on elif (random_led == 1): tree.leds_on_and_wait(L1, DELAY) # D1 on elif (random_led == 2): tree.leds_on_and_wait(L2, DELAY) # D2 on elif (random_led == 3): tree.leds_on_and_wait(L3, DELAY) # D3 on elif (random_led == 4): tree.leds_on_and_wait(L4, DELAY) # D4 on elif (random_led == 5): tree.leds_on_and_wait(L5, DELAY) # D5 on elif (random_led == 6): tree.leds_on_and_wait(L6, DELAY) # D6 on tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end # Shutdown Pi os.system('sudo halt')
import tree # Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: flash each LED in turn for i in range(5): # repeat 5 times tree.leds_on_and_wait(L0, 0.3) # LED 0 on for 0.3 seconds tree.leds_on_and_wait(L1, 0.3) # LED 1 on for 0.3 seconds tree.leds_on_and_wait(L2, 0.3) # etc. tree.leds_on_and_wait(L3, 0.3) tree.leds_on_and_wait(L4, 0.3) tree.leds_on_and_wait(L5, 0.3) tree.leds_on_and_wait(L6, 0.3) tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 dotLength = 0.1 tree.setup() # you must always call setup() first! message = raw_input("Type in a message your tree will display in morse code! - ") for char in message: if char != ' ': morse = tryEncode(char) for i in morse: if i == '.': tree.leds_on_and_wait(ALL,dotLength) tree.leds_on_and_wait(NO_LEDS,dotLength) else: tree.leds_on_and_wait(ALL,dotLength*3.0) tree.leds_on_and_wait(NO_LEDS,dotLength) sleep(dotLength*2) else: sleep(dotLength*7) tree.all_leds_off() tree.cleanup()
L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: two or three LEDs are on at the same time. # Note that each pair is on for 0.4 seconds for i in range(7): # repeat the pattern 7 times tree.leds_on_and_wait(L1+L4, 0.4) # LED 1 and LED 4 tree.leds_on_and_wait(L5+L3+L0, 0.4) # LEDs 5, 3 and 0 tree.leds_on_and_wait(L2+L6, 0.4) # LEDs 2 and 6 tree.leds_on_and_wait(L5+L3+L0, 0.4) # LEDs 5, 3 and 0 tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
def pattern3(): # blinking tree.leds_on_and_wait(ALL, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5)
# Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: all LEDs illuminated except for one each time for i in range(3): # repeat 3 times tree.leds_on_and_wait(ALL - L0, 0.5) # all on except for LED 0 tree.leds_on_and_wait(ALL - L1, 0.5) # all on except for LED 1 tree.leds_on_and_wait(ALL - L2, 0.5) # etc. tree.leds_on_and_wait(ALL - L3, 0.5) tree.leds_on_and_wait(ALL - L4, 0.5) tree.leds_on_and_wait(ALL - L5, 0.5) tree.leds_on_and_wait(ALL - L6, 0.5) tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
def pattern4(): # ascending, yellow always on tree.leds_on_and_wait(L0, 0.5) tree.leds_on_and_wait(L0+L1, 0.5) tree.leds_on_and_wait(L0+L2, 0.5) tree.leds_on_and_wait(L0+L3, 0.5) tree.leds_on_and_wait(L0+L4, 0.5) tree.leds_on_and_wait(L0+L5, 0.5) tree.leds_on_and_wait(L0+L6, 0.5)
L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Two ways of randomly illuminating LEDs (they do the # same thing but Way 1 is easier to understand whilst # Way 2 is a shorter piece of code). # Way 1 for i in range(100): # repeat 100 times random_led = random.randint(0, 6) if (random_led == 0): tree.leds_on_and_wait(L0, 0.2) # D0 on for 0.2s elif (random_led == 1): tree.leds_on_and_wait(L1, 0.2) # D1 on for 0.2s elif (random_led == 2): tree.leds_on_and_wait(L2, 0.2) # D2 on for 0.2s elif (random_led == 3): tree.leds_on_and_wait(L3, 0.2) # D3 on for 0.2s elif (random_led == 4): tree.leds_on_and_wait(L4, 0.2) # D4 on for 0.2s elif (random_led == 5): tree.leds_on_and_wait(L5, 0.2) # D5 on for 0.2s elif (random_led == 6): tree.leds_on_and_wait(L6, 0.2) # D6 on for 0.2s # Way 2 for i in range(100): # repeat 100 times random_led = random.randint(0, 6) tree.leds_on_and_wait(1<<random_led, 0.5) # randomly selected LED on for 0.2s tree.all_leds_off() # extinguish all LEDs
def pattern5(): # filling tree.leds_on_and_wait(L0, 0.5) tree.leds_on_and_wait(L6, 0.5) tree.leds_on_and_wait(L5, 0.5) tree.leds_on_and_wait(L4, 0.5) tree.leds_on_and_wait(L2, 0.5) tree.leds_on_and_wait(L1, 0.5) tree.leds_on_and_wait(L1+L0, 0.5) tree.leds_on_and_wait(L1+L6, 0.5) tree.leds_on_and_wait(L1+L5, 0.5) tree.leds_on_and_wait(L1+L4, 0.5) tree.leds_on_and_wait(L1+L2, 0.5) tree.leds_on_and_wait(L1+L3, 0.5) tree.leds_on_and_wait(L1+L3+L0, 0.5) tree.leds_on_and_wait(L1+L3+L6, 0.5) tree.leds_on_and_wait(L1+L3+L5, 0.5) tree.leds_on_and_wait(L1+L3+L4, 0.5) tree.leds_on_and_wait(L1+L3+L2, 0.5) tree.leds_on_and_wait(L1+L3+L2+L0, 0.5) tree.leds_on_and_wait(L1+L3+L2+L6, 0.5) tree.leds_on_and_wait(L1+L3+L2+L5, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L0, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L6, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L5, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L5+L0, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L5+L6, 0.5) tree.leds_on_and_wait(L1+L3+L2+L4+L5+L6+L0, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5) tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5) tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5) tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5) 82,1 34%
import tree from random import randint # Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() for i in range(100): tree.leds_on_and_wait(randint(0, 128), 0.1) tree.all_leds_off() tree.cleanup()
def pattern6(): # falling tree.leds_on_and_wait(L0, 0.5) tree.leds_on_and_wait(L0+L6, 0.5) tree.leds_on_and_wait(L0+L6+L5, 0.5) tree.leds_on_and_wait(L6+L5+L4, 0.5) tree.leds_on_and_wait(L5+L4+L2, 0.5) tree.leds_on_and_wait(L4+L2+L3+L1, 0.5) tree.leds_on_and_wait(L2+L3+L1, 0.5) tree.leds_on_and_wait(L3+L1, 0.5) tree.leds_on_and_wait(NO_LEDS, 0.5)
import tree # Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 BOTTOM_ROW = 14 MIDDLE_ROW = 48 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! for i in range(5): tree.leds_on_and_wait(BOTTOM_ROW+L0, 0.5) tree.leds_on_and_wait(MIDDLE_ROW+BOTTOM_ROW+L0, 0.5) tree.leds_on_and_wait(L6+MIDDLE_ROW+BOTTOM_ROW+L0, 0.5) tree.leds_on_and_wait(L0, 0.5) tree.all_leds_off() tree.cleanup()
def pattern7(): # blinking, yellow always on tree.leds_on_and_wait(L0, 0.5) tree.leds_on_and_wait(ALL, 0.5)
L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1+2+4+8+16+32+64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: flash each LED in turn x = 1 while x == 1: try: for i in range (2): tree.leds_on_and_wait(L0, 0.3) # LED 0 on for 0.3 seconds tree.leds_on_and_wait(L1, 0.3) # LED 1 on for 0.3 seconds tree.leds_on_and_wait(L2, 0.3) # etc. tree.leds_on_and_wait(L3, 0.3) tree.leds_on_and_wait(L4, 0.3) tree.leds_on_and_wait(L5, 0.3) tree.leds_on_and_wait(L6, 0.3) for i in range (2): tree.leds_on_and_wait(L4+L5, 1) tree.leds_on_and_wait(L0+L2, 1) tree.leds_on_and_wait(L3+L6+L1, 1) for i in range (3): tree.leds_on_and_wait(ALL, 0.8) tree.leds_on_and_wait(NO_LEDS, 0.8)
def pattern8(): # random LED on rand_led = random.randint(0, 6) tree.leds_on_and_wait(1<<rand_led, 0.5) # == 2**rand_led
import tree # Some constants to identify each LED L0 = 1 L1 = 2 L2 = 4 L3 = 8 L4 = 16 L5 = 32 L6 = 64 ALL = 1 + 2 + 4 + 8 + 16 + 32 + 64 NO_LEDS = 0 tree.setup() # you must always call setup() first! # Pattern: two or three LEDs are on at the same time. # Note that each pair is on for 0.4 seconds for i in range(7): # repeat the pattern 7 times tree.leds_on_and_wait(L1 + L4, 0.4) # LED 1 and LED 4 tree.leds_on_and_wait(L5 + L3 + L0, 0.4) # LEDs 5, 3 and 0 tree.leds_on_and_wait(L2 + L6, 0.4) # LEDs 2 and 6 tree.leds_on_and_wait(L5 + L3 + L0, 0.4) # LEDs 5, 3 and 0 tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end
L3 = 8 L4 = 16 L5 = 32 L6 = 64 AMBER = 1 # LED 0 = amber RED = 128 # LED 0 = red GREEN = 256 # LED 0 = green NO_LEDS = 0 BOTTOM6 = 2 + 4 + 8 + 16 + 32 + 64 # the 6 standard red LEDs # note that we must tell setup() that we have a bicolour LED tree.setup() # you must always call setup() first! # All the red LEDs will be permanently illuminated and we rotate # between the various colours for the bicolour LED at the top. for i in range(7): # repeat 7 times tree.leds_on_and_wait(BOTTOM6, 0.8) # top LED off tree.leds_on_and_wait(BOTTOM6 + GREEN, 0.8) # top LED green tree.leds_on_and_wait(BOTTOM6 + RED, 0.8) # top LED red tree.leds_on_and_wait(BOTTOM6 + AMBER, 0.8) # top LED amber tree.leds_on_and_wait(NO_LEDS, 0.8) # all LEDs off tree.leds_on_and_wait(GREEN, 0.8) # top LED green tree.leds_on_and_wait(RED, 0.8) # top LED red tree.leds_on_and_wait(AMBER, 0.8) # top LED amber tree.all_leds_off() # extinguish all LEDs # All done! tree.cleanup() # call cleanup() at the end