def draw(self): lcd = LCD() lcd.fillScreen(LCD.color.BLACK) lcd.setTextColor(LCD.color.WHITE, LCD.color.DARKGREY) if IS_VIRTUAL_MACHINE: lcd.keyCallback = self.keyCallback while True: self.drawMenuButton(lcd, KeyMap.WIO_KEY_A, "CHECK", 0) self.drawMenuButton(lcd, KeyMap.WIO_KEY_B, "NEXT", 1) self.drawMenuButton(lcd, KeyMap.WIO_KEY_C, "RESET", 2) lcd.setTextColor(LCD.color.WHITE, LCD.color.BLACK) lcd.setTextSize(2) lcd.drawString("13 * 5 + 8 = ?", 50, 70) lcd.setTextSize(1) lcd.drawLine(int(60), int(0), int(60), int(20), LCD.color.WHITE) lcd.drawLine(int(120), int(0), int(120), int(20), LCD.color.WHITE) lcd.drawLine(int(180), int(0), int(180), int(20), LCD.color.WHITE) lcd.drawLine(int(0), int(20), int(180), int(20), LCD.color.WHITE) time.sleep(self.MAIN_LOOP_DELAY)
Value_SWITCH_RIGHT = 0 Value_SWITCH_PRESS = 0 # variables for reading previous button/ switch state Value_Button_A_OLD = 0 Value_Button_B_OLD = 0 Value_Button_C_OLD = 0 Value_SWITCH_UP_OLD = 0 Value_SWITCH_DOWN_OLD = 0 Value_SWITCH_LEFT_OLD = 0 Value_SWITCH_RIGHT_OLD = 0 Value_SWITCH_PRESS_OLD = 0 lcd = LCD() # TFT LCD initialization lcd.fillScreen(lcd.color.WHITE) # fill background in white # # draw lower notes with black border # lcd.drawRect(0,0,40,240,lcd.color.BLACK) # draw rectangle with black border # lcd.drawRect(40,0,40,240,lcd.color.BLACK) # lcd.drawRect(80,0,40,240,lcd.color.BLACK) # lcd.drawRect(120,0,40,240,lcd.color.BLACK) # lcd.drawRect(160,0,40,240,lcd.color.BLACK) # lcd.drawRect(200,0,40,240,lcd.color.BLACK) # lcd.drawRect(240,0,40,240,lcd.color.BLACK) # lcd.drawRect(280,0,40,240,lcd.color.BLACK) # # draw upper notes with black fill # lcd.fillRect(25,0,30,130,lcd.color.BLACK) # fill rectangle with black # lcd.fillRect(65,0,30,130,lcd.color.BLACK) # lcd.fillRect(145,0,30,130,lcd.color.BLACK)
from machine import LCD, Sprite import time, math DEG2RAD = 0.0174532925 lcd = LCD() lcd.fillScreen(lcd.color.BLACK) # DRAW CIRCLE SEGMENTS # x,y == coords of centre of circle # start_angle = 0 - 359 # sub_angle = 0 - 360 = subtended angle # r = radius # colour = 16 bit colour value def fillSegment(x, y, startAngle, subAngle, r, color): # Calculate first pair of coordinates for segment start sx = math.cos((startAngle - 90) * DEG2RAD) sy = math.sin((startAngle - 90) * DEG2RAD) x1 = sx * r + x y1 = sy * r + y # Draw colour blocks every inc degrees for i in range(startAngle, startAngle + subAngle, 1): # Calculate pair of coordinates for segment end x2 = math.cos((i + 1 - 90) * DEG2RAD) * r + x y2 = math.sin((i + 1 - 90) * DEG2RAD) * r + y lcd.fillTriangle(int(x1), int(y1), int(x2), int(y2), x, y, color) # Copy segment end to segment start for next segment
from machine import LCD import time, math M_SIZE = 1.3333 LOOP_PERIOD = 35 ltx = 0 osx = M_SIZE * 120 osy = M_SIZE * 120 updateTime = 0 old_analog = -999 d = 0 tft = LCD() tft.fillScreen(tft.color.BLACK) def valmap(value, istart, istop, ostart, ostop): return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)) def plotNeedle(value, ms_delay): global old_analog global osx, osy, ltx tft.setTextColor(tft.color.BLACK, tft.color.WHITE) if (value < -10): value = -10 # Limit value to emulate needle end stops if (value > 110): value = 110
from machine import LCD #include LCD function from machine module lcd = LCD() #initialize TFT LCD lcd.fillScreen(lcd.color.WHITE) #fill background color lcd.setRotation(3) #set screen rotation #draw for title header lcd.fillRect(0, 0, 320, 60, lcd.color.DARKGREEN) #draw rectangle with border lcd.setTextSize(3) #set text size lcd.setTextColor(lcd.color.WHITE, lcd.color.DARKGREEN) #color of text lcd.drawString("MUSIC PLAYER", 55, 15) #draw a string #draw for volume lcd.drawRoundRect(90, 75, 140, 60, 15, lcd.color.BLUE) #draw round corner rectangle with border lcd.fillTriangle(40, 105, 80, 75, 80, 135, lcd.color.RED) #draw triangle with fill color lcd.fillTriangle(280, 105, 240, 75, 240, 135, lcd.color.DARKGREEN) lcd.setTextColor(lcd.color.BLACK) lcd.drawString("VOLUME", 105, 95) #draw for play lcd.drawCircle(160, 190, 45, lcd.color.BLUE) #draw circle with fill color lcd.fillTriangle(60, 185, 100, 155, 100, 215, lcd.color.RED) lcd.fillTriangle(260, 185, 220, 155, 220, 215, lcd.color.DARKGREEN) lcd.drawString("PLAY", 130, 180)