示例#1
0
        draw_440Hz_fft_fast(sample_buffer, 0, 900, 8)
        int_fft_flag = 0

        #===========
        #FOR DEEPSLEEP
        #rep = rep - 1

        hx1 = HX711('P14', 'P10', gain=32)
        val1 = hx1.get_units(5)
        print("w1: ")
        print(val1)
        time.sleep_ms(200)

        #SPI using standard pins for DISPLAY after using SPI for HX711
        spi = SPI(SPI.MASTER, baudrate=40000000, polarity=0, phase=0)
        tft.fillrect((0, (tft.size()[1] - (sysfont["Height"] * 2))),
                     (tft.size()[0], tft.size()[1]), TFT.BLACK)

        v = tft.size()[1] - (sysfont["Height"] * 2)
        fft_print = "Weight: %4.1f" % (val1)
        tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1)
        v += sysfont["Height"]

        temp.start_conversion()
        time.sleep(1)
        print("Temp: ")
        print(temp.read_temp_async())

        fft_print = "Temp: %4.1f" % (temp.read_temp_async())
        tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1)

    # hx1.set_gain(32)
示例#2
0
class GameEngine:
    def __init__(self, screensize):
        spi = SPI(1, baudrate=20000000, polarity=0, phase=0,
                  sck=Pin(SPI_SCK), mosi=Pin(SPI_SDO), miso=None)
        # def __init__( self, spi, aDC, aReset, aCS) :
        # Pin details for SPI interface for screen
        self.tft = TFT(spi, SPI_DC, SPI_RS, SPI_CS)
        self.tft.initg()   # Change this to make screen dimensions match board i.e if you get a line around the edge driver needs rewwwok for this
        self.tft.rgb(True)
        self.tft.set_size(screensize)
        self.set_caption("Tetris")
        self.level = 2
        self.screenSize = screensize
        # Board offsets
        self.x = 4
        self.y = 10
        
        # Pin details for buttons.
        self.right_button = button(19)
        self.left_button = button(14)

    def set_caption(self, caption):
        self.tft.fill(TFT.BLACK)
        v = 30
        v += sysfont["Height"] * 2
        self.tft.text((20, v), caption, TFT.GREEN, sysfont, 2, nowrap=True)
        time.sleep_ms(1000)

    def render_text(self, aText, aColour, vPos, fSize):
        self.tft.text((8, vPos), aText, aColour, sysfont, fSize, nowrap=True)

    # Draw a grid by drawing hollow rectangles starting a smallest coordinate'''
    # Then fill the hollow retangles with colours of fallen frozen blocks '''
    # For the filled rectangle.  aStart is the smallest coordinate corner
    # and aSize is a tuple indicating width, heightalready rededuced for  the ineer block
    def draw_board(self, myTetris):
        gridLineColour = TFT.RED

        # print (' blockOuter: {0} blockInner: {1}  TWidth: {2} THeight: {3}'.format( blockOuter, blockInner, myTetris.width, myTetris.height))
      
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):

                # Render grid
                self.tft.rect((self.x + 12 * i  , self.y + 7*j ),
                             (120//10+1, 155//20+1), gridLineColour)
             
    def render_all(self,myTetris):
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):
                self.tft.fillrect((self.x + 12 * i +1 , self.y + 7 * j + 1),
                                    (11,5)  , (myTetris.field[j][i]))
                
        #print('\n'.join(' '.join(map(str,sl)) for sl in myTetris.field))
        
    def render_frozen(self,myTetris):
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):
                if myTetris.field[j][i] > 0:
                    #(120//10-2, 155//20-2)
                    self.tft.fillrect((self.x + 12 * i , self.y + 7 * j),
                                  (12,7)    , (myTetris.field[j][i]))
       
       
    def hide_figure(self,figure):
        for i in range(4):
            for j in range(4):
                p = i * 4 + j        
                if p in figure.orientation():
                    blockColor = TFT.BLACK
                    fx = figure.x
                    fy = figure.y
                    self.tft.fillrect(
                                (self.x + 12 * (j + fx) + 1, self.y + 7 * (fy + i) + 1),  (120//10-2, 155//20-1),  blockColor)
   # Render the floating blocks 
    def render_figure(self, figure):
        if figure is not None:
           # print("fig or last:" + str(figure.orientation_last()))
            for i in range(4):
                for j in range(4):
                    p = i * 4 + j
                    if p in figure.orientation_last():
                        blockColor = TFT.BLACK
                        fx = figure.x_org
                        fy = figure.y_org

                        self.tft.fillrect(
                            (self.x + 12 * (j + fx) +1 , self.y + 7 * (fy + i) +1 ), (11,5) ,  blockColor)
                for i in range(4):
                    for j in range(4):
                        p = i * 4 + j        
                        if p in figure.orientation():
                            blockColor = figure.color
                            fx = figure.x 
                            fy = figure.y

                            self.tft.fillrect(
                                (self.x + 12 * (j + fx) +1, self.y + 7 * (fy + i)+1), (11,5) ,  blockColor)


    def game_end(self):
        self.tft.fill(TFT.BLACK)
        self.render_text("Game Over", TFT.ORANGE, 50, 2)
        self.render_text("PRESS ANY KEY", TFT.ORANGE, 90, 1)

    def game_score(self, ascore):
        self.render_text("Tetris Score: " + str(ascore), TFT.ORANGE, 1, 1)

    def game_quit(self):
        self.tft.fill(TFT.BLACK)
        self.render_text("Game END", TFT.ORANGE, 50, 2)
        return
示例#3
0
tft.fill(TFT.BLACK)
v = 30
tft.text((0, v), "octopus LAB (1)", TFT.RED, sysfont, 1, nowrap=True)
v += sysfont["Height"]

tft.fill(TFT.BLACK)
tft.rotation(1)

# size = 3
cursor = Point2D(63, 81)
matrix = Point2D(63 / 3, 81 / 3)
mx = {}  # set

tft.fill(TFT.BLACK)
tft.fillrect((cursor.x, cursor.y), (4, 4), TFT.WHITE)


def position(dx, dy):
    global mx  # cursor, fb, tft
    cursor.x = cursor.x + dx * 3
    cursor.y = cursor.y + dy * 3
    matrix.x = matrix.x + dx
    matrix.y = matrix.y + dy
    mx[matrix.x] = matrix.y
    print(cursor.x, cursor.y)
    tft.fill(TFT.BLACK)
    tft.fillrect((cursor.x, cursor.y), (4, 4), TFT.WHITE)


@button_dwn.on_press