var cb[8] var noir var duree var n var min var max var moy timer.period[0]=20 motor.left.target =VIT_NORMALE motor.right.target =VIT_NORMALE onevent timer0 if prox.ground.ambiant[0]==0 then # Il y a une bande noire call leds.top(32,0,0) noir=1 # On incrémente la durée sur la bande duree++ end if prox.ground.ambiant[0]>BLANC then # On n'est pas sur une bande noire call leds.top(0,32,0) # Fin du code-barres ? #Arrêt du timer et des moteurs if n==8 then timer.period[0]=0 motor.right.target=0 motor.left.target=0 callsub affiche # Sinon on mémorise la durée sur la bande elseif noir==1 then cb[n]=duree duree=0 n++ end noir=0 end emit barres noir # Détection des bords gauche+droite if prox.horizontal[4]>DIST_BORD then motor.left.target=VIT_RALENTI motor.right.target =VIT_NORMALE end if prox.horizontal[0]>DIST_BORD then motor.right.target=VIT_RALENTI motor.left.target =VIT_NORMALE end sub affiche # On cherche la plus petite et la plus grande durée call math.stat(cb, min, max, moy) # moy sera la moyenne du min et du max moy=(min+max)/2 # Si la durée est <=moy on éteindra le led for n in 0:7 do if cb[n]<=moy then cb[n]=1 else cb[n]=32 end end call leds.circle(cb[7],cb[6],cb[5],cb[4],cb[3],cb[2],cb[1],cb[0]) return