#!/usr/bin/python #led 3d cube #by Otacon22 - Nocopy team import parallel import time import random class Cube: def __init__(self): self.p=parallel.Parallel() self.d=self.p.setData self.d(0) #spegne tutto self.d(31) #alimentazione agli integrati e z tutti spenti self.c1=0 self.c2=0 def muovi(self,num,l): l2=63 l3=31 j=int("".join(l),2) n=0 while 1: n+=1 self.d(l2) self.d(l3) if self.c1==9: self.c1==0 if self.c2==9: self.c2=0 else: self.c2+=1 else: self.c1+=1 if n==num: self.d(j) break def muovifinoa(self,cont1,cont2,l): l2=63 l3=31 j=int("".join(l),2) while 1: if self.c1==cont1 and self.c2==cont2: self.d(j) break self.d(l2) self.d(l3) if self.c1==9: self.c1=0 if self.c2==9: self.c2=0 else: self.c2+=1 else: self.c1+=1 if self.c2==9: self.c2=0 def write(self,x,y,z,z2=[]): #manda il reset a tutti e 2 i contatori self.d(223) self.c1=0 self.c2=0 l=["0","0","0","1","1","1","1","1"] #tutte le z spente if z2==[]: if z==0: l[7]="0" elif z==1: l[4]="0" elif z==2: l[6]="0" elif z==3: l[3]="0" else: for z in z2: if z==0: l[7]="0" elif z==1: l[4]="0" elif z==2: l[6]="0" elif z==3: l[3]="0" if y==0: if x==0: self.muovifinoa(8,3,l) elif x==1: self.muovifinoa(8,7,l) elif x==2: self.muovifinoa(5,8,l) elif x==3: self.muovifinoa(0,8,l) elif y==1: if x==0: self.muovifinoa(8,5,l) elif x==1: self.muovifinoa(8,0,l) elif x==2: self.muovifinoa(6,8,l) elif x==3: self.muovifinoa(3,8,l) elif y==2: if x==0: self.muovifinoa(8,4,l) elif x==1: self.muovifinoa(8,1,l) elif x==2: self.muovifinoa(7,8,l) elif x==3: self.muovifinoa(4,8,l) elif y==3: if x==0: self.muovifinoa(8,6,l) elif x==1: self.muovifinoa(8,2,l) elif x==2: self.muovifinoa(1,8,l) elif x==3: self.muovifinoa(2,8,l) if __name__=="__main__": C=Cube() time.sleep(0.1) t=0.005 m=0.1 h=0.1 for kk in range(10): for x in range(4): for y in range(4): for z in range(4): C.write(x,y,z) time.sleep(0.005) for kk in range(10): for z in range(4): for a in [ "00","01","02","03","13","23","33","32","31","30","20","10","11","12","22","21" ]: C.write(int(a[0]),int(a[1]),z) time.sleep(0.005) while 1: C.write(random.randrange(4), random.randrange(4), random.randrange(4)) time.sleep(0.005)