示例#1
0
 def renderui(self):
     self.display.fill_rectangle(0, 0, self.blocksize * self.asizex + 4,
                                 self.blocksize * self.asizey + 4,
                                 color565n(200, 200, 200))
     self.display.fill_rectangle(2, 2, self.blocksize * self.asizex,
                                 self.blocksize * self.asizey,
                                 color565n(0, 0, 0))
示例#2
0
def run():
    io = mcpnew.MCP23017(i2c, address=0x20)  # 32

    for a in pinz:
        io.setup(a, mcpnew.IN)
        io.pullup(a, True)

    display.erase()
    display.set_pos(0, 0)
    display.width = 240
    display.height = 320

    display.fill_rectangle(0, 0, 240, 320, color565n(0, 0, 30))

    tilemngr = tilemanager(display)

    tilemngr.generatelevel()

    tilemngr.renderlevel()

    while io.input(BUTTON_UP):
        if not io.input(PIN_UP):
            tilemngr.scroll(1)

        if not io.input(BUTTON_DOWN):
            display._write(0x21) #inverts display colors

        if not io.input(BUTTON_LEFT):
            display._write(0x20) #normal display colors
示例#3
0
 def filldrawbuf(self, rownum): #row 0 is bottom
     #fills row draw buffer with tiles from row rownum
     transparent = color565n(255, 0, 255)
     bsize = self.blocksize
     numblockshoriz = self.numblockshoriz
     for x in range(0, numblockshoriz):
         tileid = self.level[rownum * numblockshoriz + x]
         self.frowbuf.blit(self.tiles[tileid], x*bsize, 0, transparent)
示例#4
0
def run():
    io = mcpnew.MCP23017(i2c, address=0x20)  # 32

    for a in pinz:
        io.setup(a, mcpnew.IN)
        io.pullup(a, True)

    display.erase()
    display.set_pos(0, 0)
    display.width = 240
    display.height = 320

    display.fill_rectangle(0, 0, 240, 320, color565n(0, 0, 30))

    omraad = area(display)

    snek = snake(display, omraad)
    snek.initsnake()

    while True:
        if not io.input(PIN_LEFT):
            snek.changedirection(DIR_LEFT)

        if not io.input(PIN_RIGHT):
            snek.changedirection(DIR_RIGHT)

        if not io.input(PIN_DOWN):
            snek.changedirection(DIR_DOWN)

        if not io.input(PIN_UP):
            snek.changedirection(DIR_UP)

        #if not io.input(BUTTON_UP):
        #    break

        snek.movesnake()
示例#5
0
    def __init__(self, disp):
        self.display = disp
        self.tiles = []

        self.asizex = 30
        self.asizey = 30

        self.toppadding = 10

        self.bgcol = color565n(0, 0, 30)
        self.snekcol = color565n(180, 170, 40)
        self.wallcol = color565n(30, 30, 140)
        self.applecol = color565n(180, 40, 40)

        self.tilesize = 240 // self.asizex  #16

        self.display.set_pos(0, 0)
        self.display.set_color(color565n(220, 220, 160), color565n(0, 0, 30))
        self.display.write("score: ")

        self.initializelevel()
        self.spawnnewapple()
示例#6
0
 def crash(self):
     self.dead = True
     self.display.set_pos(80, 120)
     self.display.set_color(color565n(250, 55, 55), color565n(0, 0, 0))
     self.display.write("You crashed!!")
示例#7
0
    def __init__(self, disp):
        self.display = disp

        self.blocksize = 14

        self.asizex = 10
        self.asizey = 20

        self.gg = False

        self.ablocksflipped = 0

        self.linesremoved = 0

        self.score = 0

        self.blocks = []

        self.ablocks = []
        self.ablocksid = 1
        self.nextblocksid = 3
        self.ablocksx = 0
        self.ablocksy = 0

        self.blockshapes = [[(0, 1), (1, 1), (1, 0), (2, 0)],
                            [(0, 0), (1, 1), (1, 0), (2, 1)],
                            [(0, 0), (0, 1), (0, 2), (1, 2)],
                            [(1, 0), (1, 1), (1, 2), (0, 2)],
                            [(0, 0), (0, 1), (1, 0), (1, 1)],
                            [(1, 0), (1, 1), (0, 1), (2, 1)],
                            [(1, 0), (1, 1), (1, 2), (1, 3)]]

        self.speed = 40
        self.counter = 0

        self.level = 1
        self.levelcounter = 0

        self.display.set_pos(self.asizex * self.blocksize + 20, 20)
        self.display.set_color(color565n(220, 220, 220), color565n(0, 0, 0))
        self.display.write("next")

        self.display.set_pos(self.asizex * self.blocksize + 20, 120)
        self.display.write("score")

        self.display.set_pos(self.asizex * self.blocksize + 20, 150)
        self.display.write("lines")

        self.display.set_pos(self.asizex * self.blocksize + 20, 180)
        self.display.write("level")

        self.renderlevel()
        self.renderscore()

        self.buffer = bytearray(
            self.blocksize * self.asizex * self.blocksize * 5 *
            2)  # hele bredden, max block size 4x4 + 1 buffer over

        self.ablockbuf = framebuf.FrameBuffer(self.buffer,
                                              self.blocksize * self.asizex,
                                              self.blocksize * 5,
                                              framebuf.RGB565)

        self.nextbuffer = bytearray(self.blocksize * 4 * self.blocksize * 4 *
                                    2)
        self.nextblockbuf = framebuf.FrameBuffer(self.nextbuffer,
                                                 self.blocksize * 4,
                                                 self.blocksize * 4,
                                                 framebuf.RGB565)

        self.colors = [
            color565(0, 0, 0),
            color565(200, 0, 0),
            color565(0, 200, 0),
            color565(0, 0, 200),
            color565(150, 150, 0),
            color565(150, 150, 150),
            color565(150, 0, 150),
            color565(200, 150, 50),
            color565(50, 250, 150),
            color565(50, 50, 50)
        ]
示例#8
0
 def gameover(self):
     self.gg = True
     self.display.set_pos(((self.asizex * self.blocksize) // 2) - 25, 90)
     self.display.set_color(color565n(220, 220, 160), color565n(0, 0, 0))
     self.display.write("game over")
示例#9
0
def run():
    for a in pinz:
        io.setup(a, mcpnew.IN)
        io.pullup(a, True)

    bme = bme280_int.BME280(i2c=i2c)

    display.erase()
    display.set_pos(0, 0)
    display.width = 240
    display.height = 320

    display.fill_rectangle(0, 0, 240, 320, color565n(0, 0, 70))

    tmax = -100.0
    tmin = 100.0

    display.set_color(color565n(220, 220, 220), color565n(0, 0, 70))

    display.set_pos(120, 85)
    display.write("Pressure")

    display.set_pos(120, 158)
    display.write("Humidity")

    hmax = 0
    hmin = 100

    for a in range(0, 9):
        display.fill_rectangle(45, 30 + (a * 30), 5, 1,
                               color565n(220, 220, 220))
        display.set_pos(50, 30 + (a * 30))
        pelp = ((9 - a) - 3) * 10
        display.write(str(pelp))

    while True:

        bmevals = bme.read_compensated_data()

        temp = bmevals[0] / 100

        press = bmevals[1] // 256
        atm = press / 101325
        hg = press / 133.322
        ihg = press / 3386.389

        humid = bmevals[2] / 1024

        sizep = 240 - (int(temp) + 20) * 3
        grisep = 240 - sizep

        tmaxp = 240 - (int(tmax) + 20) * 3
        tminp = 240 - (int(tmin) + 20) * 3

        if sizep < tmaxp:
            display.fill_rectangle(20, tmaxp + 30, 5, 1, color565n(0, 0, 70))
            tmax = temp
            display.fill_rectangle(20, 240 - (int(tmin) + 20) * 3 + 30, 5, 1,
                                   color565n(20, 130, 180))
            display.fill_rectangle(20, 240 - (int(tmax) + 20) * 3 + 30, 5, 1,
                                   color565n(180, 130, 20))

        if sizep > tminp:
            display.fill_rectangle(20, tminp + 30, 5, 1, color565n(0, 0, 70))
            tmin = temp
            display.fill_rectangle(20, 240 - (int(tmax) + 20) * 3 + 30, 5, 1,
                                   color565n(180, 130, 20))
            display.fill_rectangle(20, 240 - (int(tmin) + 20) * 3 + 30, 5, 1,
                                   color565n(20, 130, 180))

        display.set_pos(20, 287)
        #display.set_color(color565n(220, 220, 220), color565n(0,0,0))
        display.write(str(temp))

        display.set_pos(120, 97)
        display.write(str(round(atm, 3)) + " atm   ")
        display.set_pos(120, 107)
        display.write(str(round(press, 0)) + " Pa   ")
        display.set_pos(120, 117)
        display.write(str(round(hg, 1)) + " mm Hg   ")
        display.set_pos(120, 127)
        display.write(str(round(ihg, 2)) + " in Hg   ")

        display.set_pos(120, 170)
        display.write(str(round(humid, 2)) + " %")

        if humid > hmax:
            hmax = humid
            display.set_pos(120, 195)
            display.write("max: " + str(round(hmax, 2)) + " %")

        if humid < hmin:
            hmin = humid
            display.set_pos(120, 205)
            display.write("min: " + str(round(hmin, 2)) + " %")

        display.fill_rectangle(30, 30, 15, sizep - 1, color565n(0, 0, 0))
        display.fill_rectangle(30, sizep + 30, 15, grisep,
                               color565n(140, 180, 140))

        if not io.input(BUTTON_UP):
            break
示例#10
0
            clk.value(1)
            clk.value(0)


pipz = [4, 7, 8, 11]

for a in pipz:
    io.setup(a, mcpnew.IN)
    io.pullup(a, True)

display.erase()
display.set_pos(0, 0)
display.width = 240
display.height = 320

display.fill_rectangle(0, 0, 240, 320, color565n(0, 0, 0))

display.set_color(color565n(220, 220, 160), color565n(0, 0, 30))

display.set_pos(50, 50)
display.write("Tetris")

display.set_pos(50, 70)
display.write("Snake")

display.set_pos(50, 90)
display.write("Weather report")

display.set_pos(50, 110)
display.write("3D dungeon")
示例#11
0
import utime