def on_draw(self): if not self.__initialized: self.__lazy_init() x_offset = 4 y_offset = 6 lcd.clear() print("progress 0") for i in range(self.current_offset, len(self.current_dir_file_info_list)): # gc.collect() print("progress 1") file_info = self.current_dir_file_info_list[i] file_name = file_info["file_name"] f_stat = file_info["stat"] if f_stat != None: if S_ISDIR(f_stat[0]): file_name = file_name + '/' file_readable_size = sizeof_fmt(f_stat[6]) lcd.draw_string(lcd.width() - 50, y_offset, file_readable_size, lcd.WHITE, lcd.BLUE) is_current = self.current_selected_index == i line = "%s %d %s" % ("->" if is_current else " ", i, file_name) lcd.draw_string(x_offset, y_offset, line, lcd.WHITE, lcd.RED) # gc.collect() print("progress 2") y_offset += 18 if y_offset > lcd.height(): print("y_offset > height(), break") break print("progress 3")
def __lazy_init(self): err_counter = 0 while 1: try: sensor.reset() # Reset sensor may failed, let's try sometimes break except Exception: err_counter = err_counter + 1 if err_counter == 20: lcd.draw_string(lcd.width() // 2 - 100, lcd.height() // 2 - 4, "Error: Sensor Init Failed", lcd.WHITE, lcd.RED) time.sleep(0.1) continue print("progress 1 OK!") sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) # QVGA=320x240 sensor.run(1) print("progress 2 OK!") self.task = kpu.load(0x300000) # Load Model File from Flash anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025) # Anchor data is for bbox, extracted from the training sets. print("progress 3 OK!") kpu.init_yolo2(self.task, 0.5, 0.3, 5, anchor) self.but_stu = 1 self.__initialized = True
def on_draw(self): self.is_dirty = False if not self.__initialized: self.__lazy_init() x_offset = 4 y_offset = 6 lcd.clear() for i in range(self.current_offset, len(self.current_dir_files)): # gc.collect() file_name = self.current_dir_files[i] print(file_name) try: f_stat = os.stat('/sd/' + file_name) if S_ISDIR(f_stat[0]): file_name = file_name + '/' # gc.collect() file_readable_size = sizeof_fmt(f_stat[6]) lcd.draw_string(lcd.width() - 50, y_offset, file_readable_size, lcd.WHITE, lcd.BLUE) except Exception as e: print("-------------------->", e) is_current = self.current_selected_index == i line = "%s %d %s" % ("->" if is_current else " ", i, file_name) lcd.draw_string(x_offset, y_offset, line, lcd.WHITE, lcd.RED) # gc.collect() y_offset += 18 if y_offset > lcd.height(): print(y_offset, lcd.height(), "y_offset > height(), break") break
def compute_features(self, register=False): img, src_point, self.roi = self.LandmarkDetector.detect_landmarks( 0.4, return_img=True) self.max_score = 0 self.id = -1 if src_point: # align face to standard position a = img.pix_to_ai() T = image.get_affine_transform(src_point, self.dst_point) a = image.warp_affine_ai(img, self.img_face, T) a = self.img_face.ai_to_pix() if register: reg_img = image.Image('logo.jpg') a = reg_img.draw_image( self.img_face, (lcd.width() // 2 - 68, lcd.height() // 2 - 20)) a = reg_img.draw_string(30, lcd.height() // 2 - 48, "Registring face", color=(0, 255, 0), scale=2, mono_space=False) a = lcd.display(reg_img) del (reg_img) time.sleep(2) a = self.img_face.pix_to_ai() # calculate face feature vector fmap = kpu.forward(self.fe_task, self.img_face) #print(fmap[:]) vector = list(map(lambda x: x / 256, fmap[:])) self.feature = kpu.face_encode(vector) for id in self.db.keys(): entry = _unhexlify(self.db[id]['vector']) score = kpu.face_compare(entry, self.feature) if score > self.max_score: self.max_score = score name = self.db[id]['name'] self.id = id if not self.max_score > self.threshold: name = 'Unknown' a = img.draw_rectangle(self.roi, color=(0x1c, 0xa2, 0xff), thickness=2) a = img.draw_string(self.roi[0], self.roi[1] - 14, ("%s %%: %.2f" % (name, self.max_score)), color=(255, 255, 255), scale=1.5, mono_space=False) a = lcd.display(img) del (img)
def initialize_camera(): err_counter = 0 while 1: try: sensor.reset() #Reset sensor may failed, let's try some times break except: err_counter = err_counter + 1 if err_counter == 20: lcd.draw_string(lcd.width() // 2 - 100, lcd.height() // 2 - 4, "Error: Sensor Init Failed", lcd.WHITE, lcd.RED) time.sleep(0.1) continue sensor.set_pixformat(sensor.RGB565) # The memory can't analyze models with resolution higher than QVGA # So better we train the model with QVGA too sensor.set_framesize(sensor.QVGA) #QVGA=320x240 #sensor.set_framesize(sensor.VGA) #VGA=640x480 # Optimze this settings to get best picture quality sensor.set_auto_exposure(False, exposure_us=500) sensor.set_auto_gain( False ) #, gain_db=100) # must turn this off to prevent image washout... sensor.set_auto_whitebal(True) # turn this off for color tracking sensor.run(1)
def boot_lcd(): lcd.init() lcd.rotation(2) #Rotate the lcd 180deg try: img = image.Image("/sd/startup.jpg") lcd.display(img) test = "test" lcd.draw_string(lcd.width() // 50, lcd.height() // 2, test, lcd.WHITE, lcd.RED) except: lcd.draw_string(lcd.width() // 50, lcd.height() // 2, "Error: Cannot find start.jpg", lcd.WHITE, lcd.RED)
def show_logo(): try: img = image.Image("/sd/picture3.jpg") lcd.display(img) time.sleep(0.5) play_sound("/sd/logo.wav") except: lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Cannot find logo.jpg", lcd.WHITE, lcd.RED)
def show_logo(): try: img = image.Image("/sd/irasutoya/wall.jpeg") set_backlight(0) lcd.display(img) for i in range(9): set_backlight(i) time.sleep(0.1) except: lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Cannot find logo.jpg", lcd.WHITE, lcd.RED)
def show_logo(vol): try: img = image.Image("/sd/logo.jpg") set_backlight(0) lcd.display(img) for i in range(9): set_backlight(i) time.sleep(0.1) play_sound("/sd/logo.wav", vol) except: lcd.draw_string(lcd.width() // 2 - 100, lcd.height() // 2 - 4, "Error: Cannot find logo.jpg", lcd.WHITE, lcd.RED)
def initialize_camera(): err_counter = 0 while 1: try: sensor.reset() #Reset sensor may failed, let's try some times break except: err_counter = err_counter + 1 if err_counter == 20: lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Sensor Init Failed", lcd.WHITE, lcd.RED) time.sleep(0.1) continue sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) #QVGA=320x240 sensor.run(1)
def show_logo(image_filename, sound_filename): try: # 画像を読み込み img = image.Image(image_filename) # バックライトの輝度を設定 set_backlight(0) # 画像をLCDに描画 lcd.display(img) # バックライトの輝度を徐々に変更 for i in range(9): set_backlight(i) time.sleep(0.1) # 音声ファイルを再生 play_sound(sound_filename) except: lcd.draw_string(lcd.width() // 2 - 100, lcd.height() // 2 - 4, "Error: Cannot find %s" % image_filename, lcd.WHITE, lcd.RED)
def __init__(self): from Maix import utils import machine if utils.gc_heap_size() != 1024 * 1024: utils.gc_heap_size(1024 * 1024) # 1MiB machine.reset() lcd.init(freq=15000000) lcd.clear() self.__w = lcd.width() self.__h = lcd.height() self.canvas = image.Image(size=(self.__w, self.__h)) self.__bg_img = None self.__bg_color = (255, 255, 255) self.canvas.draw_rectangle(0, 0, self.__w, self.__h, self.__bg_color, fill=True) # background color
def record_samples_training(self): self.classify_image(("Samples taken: %d" % (self.cap_num - 3))) if self.cap_num < self.classnumber + self.samplesnumber: index = self.classifier.add_sample_img(self.img_copy) self.cap_num += 1 if self.train_status == 0: if self.cap_num >= self.classnumber + self.samplesnumber: print("start train") img = snapshot() a = img.draw_string(lcd.width() // 2 - 68, lcd.height() // 2 - 4, "Training...", color=(0, 255, 0), scale=3, mono_space=False) lcd.display(img) del (img) #del(self.img_copy) gc.collect() time.sleep(2) self.classifier.train() print("train end") self.train_status = 1
while True: if button.value()==0: while button.value()==0: pass lcd_rotation += 1 lcd_rotation %= 4 lcd.rotation(lcd_rotation) status = 0 x=0 y=0 if HW_TOUCH: (status, x, y) = ts.read() if (status == ts.STATUS_PRESS or status == ts.STATUS_MOVE): if lcd_rotation == 0: widht,height = lcd.width(),lcd.height() x,y = y,x x = lcd.width() - x elif lcd_rotation == 1: widht,height = lcd.width(),lcd.height() elif lcd_rotation == 2: widht,height = lcd.width(),lcd.height() x,y = y,x y = lcd.height() - y elif lcd_rotation == 3: widht,height = lcd.width(),lcd.height() x = widht - x y = height - y
################################################## # import ################################################## import lcd import time import pmu ################################################## # initialize ################################################## # LCDを初期化 lcd.init(color=lcd.WHITE) # LCDの方向を設定 lcd.direction(lcd.YX_LRUD) ################################################## # main ################################################## # axp192オブジェクトを取得 axp = pmu.axp192() level = 0 while True: # バックライトの輝度を変更 level = (level + 1) % 16 axp.setScreenBrightness(level) # LCDに輝度を描画 lcd.draw_string(lcd.width() // 2, lcd.height() // 2, "level: %2d" % level) # 1秒待機 time.sleep(1)
#embed on top of the image saved in the micropython memory heap a picture of joker that is also scaled as close as possible to the face , there is not png support so you have a mask img.draw_image(image.Image("/sd/facej.jpg"),i.x(),i.y(),x_scale=scalx,y_scale=scaly,mask=image.Image("/sd/face-maskj.jpg")) #a = img.draw_rectangle(i.rect()) #path = "/sd/image"+str(random.randrange(1, 1000))+"c"+str(random.randrange(1, 99))+".jpg" #img.save(path) #print("saved image with name: "+path) #for x in range(-1,2): #for y in range(-1,2): #img.draw_string(x+i.x(), y+i.y()+(i.h()>>1), text, color=(250,205,137), scale=2,mono_space=False) #img.draw_string(i.x(), i.y()+(i.h()>>1), text, color=(119,48,48), scale=2,mono_space=False) #display on lcd the final result (not optimised low framerate) a = lcd.display(img) #buttons check for interaction button A -> white led, button B -> show battery temp currently if but_a.value() == 0 and but_stu == 1: if led_w.value() == 1: led_w.value(0) else: led_w.value(1) but_stu = 0 if but_a.value() == 1 and but_stu == 0: but_stu = 1 if but_b.value() == 0: #python lcd draw string function lcd.draw_string(lcd.width()//2-100,lcd.height()//3-4, " "+str(pmu.getTemperature())+"C ", lcd.WHITE, lcd.RED) #lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, " "+str(pmu.getBatteryDischargeCurrent())+" ", lcd.WHITE, lcd.RED) a = lcd.display(img) time.sleep(0.1) #loop ends repeat forever until poweroff a = kpu.deinit(task) sys.exit()
################################################## # import ################################################## import lcd import sensor ################################################## # initialize ################################################## # LCDを初期化 lcd.init() # LCDの方向を設定 lcd.direction(lcd.YX_LRUD) # カメラを初期化 sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.run(1) ################################################## # main ################################################## while True: # カメラ画像を取得 img = sensor.snapshot() # 画像をリサイズ resized_img = img.resize(lcd.width(), lcd.height()) # 画像をLCDに描画 lcd.display(resized_img)
import lcd from fpioa_manager import * from Maix import GPIO lcd.init() fm.register(board_info.BUTTON_A, fm.fpioa.GPIO1) btn_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP) string = "off" lcd.draw_string((lcd.width() - len(string) * 8) // 2, lcd.height() // 2 - 4, string, lcd.WHITE, lcd.BLACK) while True: if btn_a.value() == 0: if string == "off": string = "on" time.sleep(.25) else: string = "off" time.sleep(.25) lcd.clear() lcd.draw_string((lcd.width() - len(string) * 8) // 2, lcd.height() // 2 - 4, string, lcd.WHITE, lcd.BLACK)
print("------") def ft6x36_write_reg(reg_addr, buf): i2c.writeto_mem(0x38, reg_addr, buf, mem_size=8) def ft6x36_read_reg(reg_addr, buf_len): return i2c.readfrom_mem(0x38, reg_addr, buf_len, mem_size=8) ft6x36_write_reg(0x00, 0x0) ft6x36_write_reg(0x80, 0xC) ft6x36_write_reg(0x88, 0xC) data = 0 data_buf = 0 x = 0 y = 0 img = image.Image(size=(lcd.width(), lcd.height())) img.draw_rectangle(0, 0, lcd.width(), lcd.height(), fill=True, color=(255, 255, 255)) img.draw_rectangle(0, 0, 10, 80, fill=True, color=lcd.RED) img.draw_rectangle(60, 0, 10, 160, fill=True, color=lcd.GREEN) img.draw_rectangle(120, 0, 10, 240, fill=True, color=lcd.BLUE) print("lcd[{}:{}]".format(lcd.width(), lcd.height())) lcd.display(img) lcd.draw_string(lcd.width() // 2 - 68, lcd.height() // 2 - 24, "Welcome to MaixPy", lcd.WHITE, lcd.RED)
self.framebuffer[row] = self.framebuffer[row + scroll_amount] else: # No rows to copy, use an empty one self.framebuffer[row] = [0x20 for i in range(self.width)] self.cursor_row -= scroll_amount def write(self, string): string_encoded = lm1125_charset.encode(string) for character in string_encoded: self.__write_character(as_integer(character)) if __name__ == '__main__': import lcd # Assumes `lcd.write(text, row)` takes a bytestring in the lm1125 character encoding and writes it on the display in the specified row and `lcd.width()` and `lcd.height()` return its dimensions. framebuffer = LCD_framebuffer(write = lcd.write, height = lcd.height(), width = lcd.width()) while True: try: command = input('> ') except EOFError: break if command == 'clear': framebuffer.clear_screen() framebuffer.sync() elif command == 'cursor': row, column = framebuffer.get_cursor() print('Row: %i Column: %i' % (row, column))
g_selCnt = 0 return ret #-------------------- g_dbgCnt = 0 g_selCnt = -1 g_rno = 0 fileInit('/sd/models') setup() time.sleep(1) while (g_isLoop): if (g_rno == 0): g_isLoop = updateSelect() col = lcd.BLUE if g_cButton.getOn(board_info.BUTTON_B) else lcd.RED lcd.draw_string(lcd.width() - len(str(g_dbgCnt)) * 8, 0, str(g_dbgCnt), col, lcd.BLACK) #'loop:'+ g_dbgCnt += 1 if g_cButton.getOn(board_info.BUTTON_B): g_dbgCnt = 0 if g_cButton.getOn(board_info.BUTTON_A): if (g_cFiler.isSelectSettings() == False): g_cButton.reset() g_rno = 1 resetKpu() time.sleep(0.1) g_cWav.play('/sd/snd/sys_ok.wav') g_cWav.wait() else: updateKpu() if g_cButton.getOn(board_info.BUTTON_A):
try: import gc, lcd, image gc.collect() lcd.init() loading = image.Image(size=(lcd.width(), lcd.height())) loading.draw_rectangle((0, 0, lcd.width(), lcd.height()), fill=True, color=(255, 0, 0)) info = "Welcome to MaixPy" loading.draw_string(int(lcd.width() // 2 - len(info) * 5), (lcd.height()) // 4, info, color=(255, 255, 255), scale=2, mono_space=0) v = sys.implementation.version vers = 'V{}.{}.{} : maixpy.sipeed.com'.format(v[0], v[1], v[2]) loading.draw_string(int(lcd.width() // 2 - len(info) * 6), (lcd.height()) // 3 + 20, vers, color=(255, 255, 255), scale=1, mono_space=1) lcd.display(loading) del loading, v, info, vers gc.collect() finally: gc.collect()
import lcd import image import random from Maix import GPIO from fpioa_manager import fm from board import board_info ################################################## # constants ################################################## # セルの幅 CELL_WIDTH = 10 # セルの高さ CELL_HEIGHT = 10 # X方向のセル数 X_MAX = lcd.width() // CELL_WIDTH # Y方向のセル数 Y_MAX = lcd.height() // CELL_HEIGHT ################################################## # initialize ################################################## # メモリを開放 gc.mem_free() # LCDを初期化 lcd.init() # LCDの方向を設定 lcd.direction(lcd.YX_LRUD) # レジスタを設定
# fftEqualizer - By: Sahil Rastogi - Sat Nov 21 2020 from Maix import GPIO from Maix import I2S from Maix import FFT from fpioa_manager import fm from modules import ws2812 import lcd, time, random lcd.init(color=(0, 0, 255)) lcd.draw_string(lcd.width() // 2 - 54, lcd.height() // 2 - 4, "fftEqualizer", lcd.WHITE, lcd.BLUE) ledPin, ledNum = 24, 150 #24 is digitalPin 5 of Maixduino ws = ws2812(led_pin=ledPin, led_num=ledNum) for i in range(ledNum): ws.set_led(i, (0, 0, 0)) ws.display() fm.register(20, fm.fpioa.I2S0_IN_D0, force=True) fm.register(19, fm.fpioa.I2S0_WS, force=True) fm.register(18, fm.fpioa.I2S0_SCLK, force=True) rx = I2S(I2S.DEVICE_0) rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode=I2S.STANDARD_MODE) sampleRate = 38640 rx.set_sample_rate(sampleRate) samplePoints = 1024 fftPoints = 128 # 64, 128, 256, 512 histNum = 10 # should ideally be equal to fftPoints
SH200Q_ACC_CONFIG = 0x0E SH200Q_GYRO_CONFIG = 0x0F SH200Q_GYRO_DLPF = 0x11 SH200Q_FIFO_CONFIG = 0x12 SH200Q_ACC_RANGE = 0x16 SH200Q_GYRO_RANGE = 0x2B SH200Q_OUTPUT_ACC = 0x00 SH200Q_OUTPUT_GYRO = 0x06 SH200Q_OUTPUT_TEMP = 0x0C SH200Q_REG_SET1 = 0xBA SH200Q_REG_SET2 = 0xCA SH200Q_ADC_RESET = 0xC2 SH200Q_SOFT_RESET = 0x7F SH200Q_RESET = 0x75 x_zero = lcd.width() // 2 y_zero = lcd.height() // 2 x_zero_rot = x_zero y_zero_rot = y_zero ################################################## # initialize ################################################## # LCDを初期化 lcd.init() # LCDの方向を設定 lcd.direction(lcd.YX_LRUD) ################################################## # function
class ui: alpha, img, anime, bak = 0, None, None, None bg_path = os.getcwd() + "/res/images/bg.jpg" logo_path = os.getcwd() + "/res/images/logo.jpg" height, weight = lcd.height(), lcd.width() enable = True def warp_template(func): def tmp_warp(warp=None): if warp: return lambda *args: [func(), warp()] return tmp_warp def blank_draw(): if ui.enable: ui.canvas = image.Image( size=(ui.height, ui.weight)) # 10ms # 168.75kb (112kb) def grey_draw(): if ui.enable: ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight), fill=True, color=(75, 75, 75)) def bg_in_draw(): if ui.enable: #ui.canvas.draw_rectangle((0, 0, ui.height, ui.weight), #fill=True, color=(75, 75, 75)) #if ui.bak == None: #ui.bak.draw_rectangle((60,30,120,150), fill=True, color=(250, 0, 0)) #ui.bak.draw_string(70, 40, "o", color=(255, 255, 255), scale=2) #ui.bak.draw_string(80, 10, "s", color=(255, 255, 255), scale=15) ui.canvas.draw_circle(121, 111, int(50), color=(64, 64, 64), thickness=3) # 10ms ui.canvas.draw_circle(120, 110, int(50), color=(250, 0, 0)) # 10ms ui.canvas.draw_circle(120, 110, int(50), fill=True, color=(250, 0, 0)) # 10ms sipeed = b'\x40\xA3\x47\x0F\x18\x38\x18\x0F\x07\x03\x00\x00\x00\x0F\x0F\x0F\x00\xFC\xFC\xFC\x00\x00\x00\xF0\xF8\xFC\x06\x07\x06\xFC\xF8\xF0' ui.canvas.draw_font(88, 80, 16, 16, sipeed, scale=4, color=(64, 64, 64)) ui.canvas.draw_font(86, 78, 16, 16, sipeed, scale=4, color=(255, 255, 255)) # ui.canvas = ui.canvas # 15ms #ui.canvas = ui.bak.copy() # 10ms 282kb def bg_draw(): if ui.enable: if ui.bak == None: ui.bak = image.Image(ui.bg_path) # 90ms ui.canvas.draw_image(ui.bak, 0, 0) # 20ms def help_in_draw(): if ui.enable: ui.canvas.draw_string(30, 6, "<", (255, 0, 0), scale=2) ui.canvas.draw_string(60, 6, "ENTER/HOME", (255, 0, 0), scale=2) ui.canvas.draw_string(200, 6, ">", (255, 0, 0), scale=2) ui.canvas.draw_string(10, ui.height - 30, "RESET", (255, 0, 0), scale=2) ui.canvas.draw_string(178, ui.height - 30, "POWER", (255, 0, 0), scale=2) def anime_draw(alpha=None): if ui.enable: if alpha == None: alpha = math.cos(math.pi * ui.alpha / 32) * 80 + 170 ui.alpha = (ui.alpha + 1) % 64 if ui.anime == None: ui.anime = image.Image(ui.logo_path) # 90ms ui.canvas.draw_image(ui.anime, 70, 70, alpha=int(alpha)) # 15ms def anime_in_draw(alpha=None): if ui.enable: if alpha == None: alpha = math.cos(math.pi * ui.alpha / 100) * 200 ui.alpha = (ui.alpha + 1) % 200 r, g, b = random.randint(120, 255), random.randint( 120, 255), random.randint(120, 255) ui.canvas.draw_circle(0, 0, int(alpha), color=(r, g, b), thickness=(r % 5)) # 10ms ui.canvas.draw_circle(0, 0, 200 - int(alpha), color=(r, g, b), thickness=(g % 5)) # 10ms ui.canvas.draw_circle(240, 0, int(alpha), color=(r, g, b), thickness=(b % 5)) # 10ms ui.canvas.draw_circle(240, 0, 200 - int(alpha), color=(r, g, b), thickness=(r % 5)) # 10ms ui.canvas.draw_circle(0, 240, int(alpha), color=(r, g, b), thickness=(g % 5)) # 10ms ui.canvas.draw_circle(0, 240, 200 - int(alpha), color=(r, g, b), thickness=(b % 5)) # 10ms ui.canvas.draw_circle(240, 240, int(alpha), color=(r, g, b), thickness=(r % 5)) # 10ms ui.canvas.draw_circle(240, 240, 200 - int(alpha), color=(r, g, b), thickness=(g % 5)) # 10ms def display(): # 10ms try: if ui.canvas != None: lcd.display(ui.canvas) finally: try: if ui.canvas != None: tmp = ui.canvas ui.canvas = None del tmp except Exception as e: pass
import lcd lcd.init() s = "ABC" lcd.draw_string((lcd.width()-len(s)*8)//2, lcd.height()//2-4, s, lcd.RED, lcd.BLACK)
except: err_counter = err_counter + 1 if err_counter == 20: lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Sensor Init Failed", lcd.WHITE, lcd.RED) time.sleep(0.1) continue sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) #QVGA=320x240 sensor.run(1) try: img = image.Image("/sd/startup.jpg") lcd.display(img) except: lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Cannot find start.jpg", lcd.WHITE, lcd.RED) time.sleep(2) if checkForM5StickV() == False: while 1: time.sleep(1) initialize_camera() currentDirectory = 1 if "sd" not in os.listdir("/"): lcd.draw_string(lcd.width()//2-96,lcd.height()//2-4, "Error: Cannot read SD Card", lcd.WHITE, lcd.RED) try:
# end of pmu_axp173.py if __name__ == "__main__": import time # tmp = I2C(I2C.I2C1, freq=100*1000, scl=30, sda=31) tmp = I2C(I2C.I2C1, freq=100 * 1000, scl=24, sda=27) axp173 = AXP173(tmp) axp173.enable_adc(True) # 默认充电限制在 4.2V, 190mA 档位 axp173.setEnterChargingControl(True) axp173.exten_output_enable() from ui_canvas import ui ui.height, ui.weight = int(lcd.width()), int(lcd.height() / 2) @ui.warp_template(ui.blank_draw) def test_pmu_axp173_draw(): global axp173 tmp = [] work_mode = axp173.getPowerWorkMode() tmp.append("WorkMode:" + hex(work_mode)) # 检测 电池电压 vbat_voltage = axp173.getVbatVoltage() tmp.append("vbat_voltage: {0} V".format(vbat_voltage)) # 检测 电池充电电流 BatteryChargeCurrent = axp173.getBatteryChargeCurrent()
data_packet.append(d % 256) uart_Port.write(data_packet) print("send " + str(d)) pmu = axp192() pmu.enablePMICSleepMode(True) lcd.init() lcd.rotation(2) #Rotate the lcd 180deg try: img = image.Image("/flash/startup.jpg") lcd.display(img) except: lcd.draw_string(lcd.width() // 2 - 100, lcd.height() // 2 - 4, "Error: Cannot find start.jpg", lcd.WHITE, lcd.RED) from Maix import I2S, GPIO import audio from Maix import GPIO from fpioa_manager import * fm.register(board_info.SPK_SD, fm.fpioa.GPIO0) spk_sd = GPIO(GPIO.GPIO0, GPIO.OUT) spk_sd.value(1) #Enable the SPK output fm.register(board_info.SPK_DIN, fm.fpioa.I2S0_OUT_D1) fm.register(board_info.SPK_BCLK, fm.fpioa.I2S0_SCLK) fm.register(board_info.SPK_LRCLK, fm.fpioa.I2S0_WS)
i_head_y = y_same_x.index(self.head.y) dy_u = self.head.y - y_same_x[i_head_y - 1] dy_d = y_same_x[i_head_y + 1] - self.head.y d = [dx_r, dy_d, dx_l, dy_u] front = d[self.direction] right = d[(self.direction + 1) % 4] left = d[(self.direction - 1) % 4] # look how far the apple is d_apple = math.sqrt(((self.head.x - self.apple.x)**2) + ((self.head.y - self.apple.y)**2)) self.observation = [1 / left, 1 / front, 1 / right, 1 / d_apple] if __name__ == '__main__': lcd.init() game = Game(lcd.width(), lcd.height()) while True: while True: utime.sleep(DELAY) # choose random turn for now action = random.randint(-1, 1) game_over, score = game.play(action) if game_over: break print(game.observation) lcd.clear() lcd.draw_string(lcd.width() // 4, lcd.height() // 2, "GAME OVER", lcd.RED, lcd.BLACK) lcd.draw_string(lcd.width() // 4, lcd.height() * 2 // 3, "Score: {}".format(score),