Skip to content
Snippets Groups Projects
Commit 8085e77c authored by Baviere Merlin's avatar Baviere Merlin
Browse files

fin BE5

parent 58ffdf47
No related branches found
No related tags found
No related merge requests found
File added
import pyb import pyb
import os
data = "X8"; # patte connectée à l'entrée série du MAX7219 (DIN) data = "X8"; # patte connectée à l'entrée série du MAX7219 (DIN)
load = "X5"; # patte de chargement des données (CS) load = "X5"; # patte de chargement des données (CS)
...@@ -83,16 +85,196 @@ def setPixel(x,y,on,bitmap): ...@@ -83,16 +85,196 @@ def setPixel(x,y,on,bitmap):
if (bitmap[x]%(pow(2,(8-y))))//(pow(2,(7-y)))==1: if (bitmap[x]%(pow(2,(8-y))))//(pow(2,(7-y)))==1:
bitmap[x]-=pow(2,(7-y)) bitmap[x]-=pow(2,(7-y))
for i in range(8): def getPixel(x,y,bitmap):
bitmap[i]=i return (bitmap[x]%(pow(2,(8-y))))//(pow(2,(7-y)))==1
updateDisplay(bitmap)
print(bitmap) def testPixels():
setPixel(5,5,False,bitmap) bitmap = bytearray(8)
print(bitmap) matrixOn(1)
updateDisplay(bitmap) matrixTest(0)
matrixDecode(0)
matrixDigits(7)
clearDisplay(bitmap)
# Trace un O
setPixel(1,2,1, bitmap); setPixel(2,2,1, bitmap); setPixel(3,2,1, bitmap)
setPixel(1,3,1, bitmap); setPixel(3,3,1, bitmap)
setPixel(1,4,1, bitmap); setPixel(3,4,1, bitmap)
setPixel(1,5,1, bitmap); setPixel(2,5,1, bitmap); setPixel(3,5,1, bitmap)
# Trace un K
setPixel(5,2,1, bitmap); setPixel(7,2,1, bitmap)
setPixel(5,3,1, bitmap); setPixel(6,3,1, bitmap)
setPixel(5,4,1, bitmap); setPixel(6,4,1, bitmap)
setPixel(5,5,1, bitmap); setPixel(7,5,1, bitmap)
updateDisplay(bitmap)
def testPixels2():
bitmap = bytearray(8)
matrixOn(True)
matrixTest(False)
matrixDecode(False)
matrixDigits(7)
clearDisplay(bitmap)
x = 0
y = 0
while True:
setPixel(x, y, True, bitmap)
updateDisplay(bitmap)
setPixel(x, y, False, bitmap)
x = (x + 1) % 8
if x == 0:
y = (y + 1) % 8
pyb.delay(100)
smiley = (
" **** ",
" * * ",
"* * * *",
"* *",
"* * * *",
"* ** *",
" * * ",
" **** "
)
frowney = (
" **** ",
" * * ",
"* * * *",
"* *",
"* ** *",
"* * * *",
" * * ",
" **** "
)
def displayPict(pict):
bitmap = bytearray(8)
clearDisplay(bitmap)
i = 0
for line in pict:
j = 0
for char in line:
if char== "*":
setPixel(i,j,1,bitmap)
j+=1
i+=1
updateDisplay(bitmap)
return bitmap
def randomBitmap():
bitmap = bytearray(8)
for i in range(8):
for j in range(8):
setPixel(i,j,(os.urandom(1)[0] > 127) ,bitmap)
return bitmap
def countNeighbours(x, y, bitmap):
vois = 0
list_vois=[((x + dx) % 8, (y + dy) % 8) for dx in (-1, 0, 1) for dy in (-1, 0, 1) if (dx, dy) != (0, 0)]
for i in list_vois:
if getPixel(i[0],i[1],bitmap):
vois+=1
return vois
def lifeStep(bitmap):
res_bitmap = bytearray(8)
for x in range(8):
for y in range(8):
if countNeighbours(x,y,bitmap)==3:
setPixel(x,y,True,res_bitmap)
elif countNeighbours(x,y,bitmap)==2:
setPixel(x,y,getPixel(x,y,bitmap),res_bitmap)
else:
setPixel(x,y,False,res_bitmap)
for i in range(8):
bitmap[i]=res_bitmap[i]
updateDisplay(bitmap)
def gameOfLife():
bitmap = randomBitmap()
while True:
pyb.delay(200)
lifeStep(bitmap)
# Figures stables
stableBlock = (
" ",
" ",
" ",
" ** ",
" ** ",
" ",
" ",
" "
)
def testBlock():
bitmap = displayPict(stableBlock)
pyb.delay(500)
lifeStep(bitmap)
stableTube = (
" ",
" ",
" * ",
" * * ",
" * ",
" ",
" ",
" "
)
def testTube():
bitmap = displayPict(stableTube)
pyb.delay(500)
lifeStep(bitmap)
# Figures oscillantes
oscBlinker = (
" ",
" ",
" ",
" *** ",
" ",
" ",
" ",
" "
)
def testBlinker():
bitmap = displayPict(oscBlinker)
for i in range(2):
pyb.delay(500)
lifeStep(bitmap)
# Vaisseaux
shipGlider = (
" ",
" ",
" ",
" ",
" ",
"*** ",
" * ",
" * "
)
def testGlider():
bitmap = displayPict(shipGlider)
for i in range(32):
pyb.delay(500)
lifeStep(bitmap)
shipLWSS = (
" ",
" ",
"* * ",
" * ",
"* * ",
" **** ",
" ",
" "
)
def testLWSS():
bitmap = displayPict(shipLWSS)
for i in range(16):
pyb.delay(500)
lifeStep(bitmap)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment