def TFT_setup(self, spi, dc, reset, cs): # setup TFT tft = TFT(spi=spi, aDC=dc, aReset=reset, aCS=cs) tft.initr() tft.rgb(True) tft.rotation(3) tft.fill(tft.BLACK) tft.text((0, 0), ESPCAM_VERSION, tft.WHITE, terminalfont) return tft
from ST7735 import TFT from sysfont import sysfont from machine import SPI, Pin import time import math spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) tft = TFT(spi, 16, 17, 18) tft.initr() tft.rgb(True) def testlines(color): tft.fill(TFT.BLACK) for x in range(0, tft.size()[0], 6): tft.line((0, 0), (x, tft.size()[1] - 1), color) for y in range(0, tft.size()[1], 6): tft.line((0, 0), (tft.size()[0] - 1, y), color) tft.fill(TFT.BLACK) for x in range(0, tft.size()[0], 6): tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color) for y in range(0, tft.size()[1], 6): tft.line((tft.size()[0] - 1, 0), (0, y), color) tft.fill(TFT.BLACK)
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
from machine import Pin, SPI, Timer from ST7735 import TFT from sysfont import sysfont #from time import sleep_ms # SETUP THE TFT DISPLAY USING SPI spi = SPI(0, 1000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)) print(spi) tft = TFT(spi, 22, 21, 20) # DC, RST, CS tft.initr() tft.rgb() tft.rotation(2) tft.fill(TFT.BLACK) tft.text((5, 70), "eFreq >>", TFT.GREEN, sysfont, 1) tft.text((5, 80), "eTicks >>", TFT.GREEN, sysfont, 1) # SETUP INTERRUPT COUNTER & PICO IRQ PIN motorEncoderCnt = 0 motorEncoderPin = Pin(6, Pin.IN, Pin.PULL_UP) #setup the interrupt pin on the pico val_old = 0 # SETUP THE CALLBACK FUNCTION ON RECEIPT OF AN INTERRUPT def motorEncoderCallback(motorEncoderPin): global motorEncoderCnt motorEncoderCnt += 1 # increment the encoder count by 1 for every interrrupt pulse # SETUP THE INTERRUPT AND START LISTENING FOR PULSES motorEncoderPin.irq(trigger=Pin.IRQ_FALLING, handler=motorEncoderCallback)
valid_tone = 'eagc' invalid_tone = 'cgae' rhythm = l*[4] #---RDM6300--- uart1 = UART(1, baudrate=9600, tx=39, rx=16) # 39 possiblement à changer buf = bytearray(4) # 4 changeable #---RC522---- rdr = mfrc522.MFRC522(14, 13, 12, 5, 21) #---ST735--- spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(27), mosi=Pin(32), miso=Pin(12)) tft=TFT(spi,33,17,18) tft.initg() tft.rgb(False) tft.fill(TFT.BLACK) #--------bouvcle principale------------ while True: #---lecture ID (125kHz)---# if uart1.any(): uart1.readinto(buf) # UART.read([nbytes]) ou sinon UART.readinto(buf[, nbytes]) ID = bytes(buf) #---lecture ID (13MHz)---# (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll()
class RINGO(object): def __init__(self): self.font1 = { "Width": 6, "Height": 8, "Start": 32, "End": 127, "Data": bytearray([ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x5F, 0x06, 0x00, 0x00, 0x07, 0x03, 0x00, 0x07, 0x03, 0x00, 0x24, 0x7E, 0x24, 0x7E, 0x24, 0x00, 0x24, 0x2B, 0x6A, 0x12, 0x00, 0x00, 0x63, 0x13, 0x08, 0x64, 0x63, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x41, 0x00, 0x00, 0x00, 0x00, 0x41, 0x3E, 0x00, 0x00, 0x00, 0x08, 0x3E, 0x1C, 0x3E, 0x08, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x62, 0x51, 0x49, 0x49, 0x46, 0x00, 0x22, 0x49, 0x49, 0x49, 0x36, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x2F, 0x49, 0x49, 0x49, 0x31, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0xEC, 0x6C, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x55, 0x1E, 0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x30, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7F, 0x02, 0x04, 0x02, 0x7F, 0x00, 0x7F, 0x02, 0x04, 0x08, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x7F, 0x09, 0x09, 0x19, 0x66, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x3F, 0x40, 0x3C, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, 0x71, 0x49, 0x45, 0x43, 0x00, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x7F, 0x44, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x38, 0x44, 0x44, 0x44, 0x7F, 0x00, 0x38, 0x54, 0x54, 0x54, 0x08, 0x00, 0x08, 0x7E, 0x09, 0x09, 0x00, 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00, 0x7F, 0x04, 0x04, 0x78, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x40, 0x00, 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x00, 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00, 0x7C, 0x04, 0x04, 0x78, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0xFC, 0x44, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0xFC, 0x00, 0x44, 0x78, 0x44, 0x04, 0x08, 0x00, 0x08, 0x54, 0x54, 0x54, 0x20, 0x00, 0x04, 0x3E, 0x44, 0x24, 0x00, 0x00, 0x3C, 0x40, 0x20, 0x7C, 0x00, 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x3C, 0x60, 0x30, 0x60, 0x3C, 0x00, 0x6C, 0x10, 0x10, 0x6C, 0x00, 0x00, 0x9C, 0xA0, 0x60, 0x3C, 0x00, 0x00, 0x64, 0x54, 0x54, 0x4C, 0x00, 0x00, 0x08, 0x3E, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x3E, 0x08, 0x00, 0x02, 0x01, 0x02, 0x01, 0x00, 0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C ]) } #updated pins/buttons self.BTN_1 = 0 self.BTN_2 = 1 self.BTN_3 = 2 self.BTN_4 = 3 self.BTN_5 = 4 self.BTN_6 = 5 self.BTN_7 = 6 self.BTN_8 = 7 self.BTN_9 = 8 self.BTN_ASTERISK = 9 self.BTN_0 = 10 self.BTN_HASHTAG = 11 self.BTN_FUN_RIGHT = 12 self.BTN_FUN_LEFT = 15 self.BTN_A = 16 self.BTN_B = 17 #obsolete buttons, successor - readJoystickX/Y() # self.BTN_UP = 18 # self.BTN_DOWN = 19 # self.BTN_LEFT = 20 # self.BTN_RIGHT = 21 self._BL_PIN = 21 self._PIXELS_PIN = 12 self._SIM_PIXELS_ENABLE_PIN = 26 self._NUM_PIXELS = 8 self.i2c = I2C(scl=Pin(27), sda=Pin(14), freq=100000) #ok self.buttons = buttons() #self.buttons = PCA9539(self.i2c, 0x21) #21 for main buttons, 20 for numerical keypad self.spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) #ok self.display = TFT(self.spi, 0, 2, 4) #ok self.display.initr() self.display.rgb(True) self.display.rotation(1) #rotation changed to 1 (top left) self.display.fill(0) self.pixels = NeoPixel(Pin(self._PIXELS_PIN, Pin.OUT), self._NUM_PIXELS, timing=True) self.BLACK = 0 self.RED = self.display.RED self.MAROON = self.display.MAROON self.GREEN = self.display.GREEN self.FOREST = self.display.FOREST self.BLUE = self.display.BLUE self.NAVY = self.display.NAVY self.CYAN = self.display.CYAN self.YELLOW = self.display.YELLOW self.PURPLE = self.display.PURPLE self.WHITE = self.display.WHITE self.GRAY = self.display.GRAY Pin(self._BL_PIN, Pin.OUT).value(0) def collideRectRect(self, x1, y1, w1, h1, x2, y2, w2, h2): return (x2 < x1 + w1 and x2 + w2 > x1 and y2 < y1 + h1 and y2 + h2 > y1) def backlight(self, bl): PWM(Pin(self._BL_PIN)).duty(bl) return def cls(self): print("\x1B\x5B2J", end="") print("\x1B\x5BH", end="") return