from machine import Pin
from neopixel import NeoPixel
import random
import time
pin=Pin(14,Pin.OUT)
np = NeoPixel(pin,64)
boutton=Pin(15,Pin.OUT)
tab=[[0,1,2,3,4,5,6,7],
[8,9,10,11,12,13,14,15],
[16,17,18,19,20,21,22,23],
[24,25,26,27,28,29,30,31],
[32,33,34,35,36,37,38,39],
[40,41,42,43,44,45,46,47],
[48,49,50,51,52,53,54,55],
[56,57,58,59,60,61,62,63]]
game=False
#if button.value_read16()==0:
# game=True
val_x = machine.ADC(27)
val_y = machine.ADC(26)
z_switch = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP)
direction=0
a=0
b=0
c=[]
cIs=False
log=[]
taille=1
while True:
for i in range len(log):
np[log[i]]
if cIs==False:
c=[random(0,64)]#utiliser le log pour generer un c dans un endroit pas ocupper
np[c]=(0,1,0)
if cIs==True and tab[a][b]==c:
cIs=False
c.pop()
taille+=1
if len(log)>taille:
del log[0]
print(direction)
if direction==0:#x=-1 alors va à gauche
log.append[tab[a][b]]
b-=1
time.sleep(0.7)
if len(log)>taille:
del log[0]
if val_y.read_u16()==0:
direction=-1
if val_y.read_u16()==65535:
direction=1
if direction == -1:#alors vas vers le bas
log.append[tab[a][b]]
a+=1
time.sleep(0.7)
if len(log)>taille:
del log[0]
if val_x.read_u16()==65535:
direction=2
if val_x.read_u16()==0:
direction=-2
if direction == 2:#alors va vers la gauche
log.append[tab[a][b]]
b+=1
time.sleep(0.7)
if len(log)>taille:
del log[0]
if val_y.read_u16()==0:
direction=-1
if val_y.read_u16()==65535:
direction=1
if direction == 1:#alors va vers le haut
log.append[tab[a][b]]
a-=1
time.sleep(0.7)
if len(log)>taille:
del log[0]
if val_x.read_u16()==65535:
direction=2
if val_x.read_u16()==0:
direction=-2
if direction == -2:#alors va vers la droite
log.append[tab[a][b]]
b-=1
time.sleep(0.7)
if len(log)>taille:
del log[0]
if val_y.read_u16()==0:
direction=-1
if val_y.read_u16()==65535:
direction=1
#---------------------------------------
#-------------joystick------------------
#---------------------------------------