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
# some constants to identify each LED L1 = 2 L2 = 4 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
def pattern8(): # random LED on rand_led = random.randint(0, 6) tree.leds_on_and_wait(1<<rand_led, 0.5) # == 2**rand_led 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) tree.setup() print("Christmas Tree Light. To stop press CTRL + C") while True: try: random_led = random.randint(1, 9) # print random_led # just for information if random_led == 1: for y in range(4): pattern1() elif random_led == 2: for y in range(4): pattern2() elif random_led == 3: for y in range(10): pattern3()
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()
import player import maze import tree file = open("sample.txt", "r") #open map file lines = file.readlines() #read file map_d = maze.Maze() #construct map_d.setup(lines) #data processing phase map_d.print() #print maze goal_cord = map_d.FindGoal(map_d.GetHeads()) player = player.Player() player.PrintLoc() tree_node = tree.TreeNode(player.GetPos()) tree = tree.Tree(tree_node) tree.setup(tree.root,player,goal_cord,"",map_d.GetHeads(),[]) print("Have any solution been found? Lets see...") tree.SearchSolution(tree.root,[]) print("done!")