#Initialisierung der Oxocard try: from machine import Pin, deepsleep, ADC, reset from globals import __np import time Pin(2, Pin.OUT).value(1) # audio ampli on Pin(15, Pin.OUT).value(0) # neopix on __np.set(37, 0xffff00, update = True) # Möglichkeit zum Ausschalten... for i in range(50): if Pin(13, Pin.IN, Pin.PULL_DOWN).value() == 1 and Pin(27, Pin.IN, Pin.PULL_DOWN).value() == 1: print("Power off") for k in [250, 100, 50, 20, 10, 5, 1, 0]: for i in range(8): __np.set(9*i+1, k << 16, update = False) __np.set(7*i+8, k << 16, update = False) __np.show() time.sleep(0.5) Pin(2, Pin.OUT).value(0) # audio ampli off Pin(15, Pin.OUT).value(1) # neopix off deepsleep() time.sleep(0.02) except ImportError: pass ################################### # Start vom eigentlichen Programm # ################################### from oxocard import * from oxoaccelerometer import * import random def myArrayShuffle(a): # Zufälliges verwürfeln eines Arrays l = len(a) for i in range(l): j = random.randint(i,l-1) a[i],a[j] = a[j],a[i] acc = Accelerometer.create() while True: enableRepaint(False) for i in range(8): dot(4,i,BLUE) dot(3,1,BLUE) dot(2,2,BLUE) dot(5,1,BLUE) dot(6,2,BLUE) dot(3,6,BLUE) dot(2,5,BLUE) dot(5,6,BLUE) dot(6,5,BLUE) repaint() # Random seed from accelerometer while True: r = abs(acc.getX()*acc.getY()*acc.getZ()) if r>150: random.seed(int(r*10000)) break clear(BLUE) repaint() # Build Labyrinth setOrigin(0,0) clear(GREEN) for x in range(24): for y in range(24): if (x==0 or y==0 or x>21 or y>21): dot(x,y,BLUE) elif x%2==1 and y%2==1: dot(x,y,RED) dot(1,1,BLACK) todo = [(1,1)] dirs = ((1,0),(0,1),(-1,0),(0,-1)) ind = [0,1,2,3] while len(todo)>0: myArrayShuffle(ind) # myArrayShuffle(todo) index = max(len(todo)-1-int(random.randint(0,100)**2/2000),0) pos = todo[index] del todo[index] for d in ind: a,b = pos[0]+dirs[d][0], pos[1]+dirs[d][1] if getColor(a, b)==GREEN: aa,bb = a+dirs[d][0], b+dirs[d][1] if getColor(aa,bb)==RED: dot(a,b,BLACK) dot(aa,bb,BLACK) todo.append(pos) todo.append((aa,bb)) break repaint() # Init Game x,y = 1,1 dot(x,y,RED) cx,cy = 0,0 enableRepaint(True) delay=0.25 while True: ang = (acc.getRoll(),acc.getPitch()) moved = False for i in range(2): for d in (-1,1): if ang[i]*d>10 and getColor(x-cx+d*(1-i),y-cy+d*i)==BLACK: dot(x-cx,y-cy,BLACK) x+=d*(1-i) y+=d*i dot(x-cx,y-cy,RED) moved = True if not moved: delay=0.25 else: delay*=0.8 sleep(delay) if x==21 and y==21: for k in [250, 100, 50, 20, 10, 5, 1, 0]: clear((0,k,0)) sleep(0.1) break cx, cy = min(max(x-4,0),16),min(max(y-4,0),16) setOrigin(cx,cy)