0% found this document useful (0 votes)
9 views3 pages

Duck System1.0

The document is a Python script for a microcontroller that interfaces with an OLED display and buttons to manage text files. It allows users to input a filename, read the corresponding text file, and display its contents on the OLED screen. The script includes functions for navigating menus and handling user input through button presses.

Uploaded by

weiyanwang096
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Duck System1.0

The document is a Python script for a microcontroller that interfaces with an OLED display and buttons to manage text files. It allows users to input a filename, read the corresponding text file, and display its contents on the OLED screen. The script includes functions for navigating menus and handling user input through button presses.

Uploaded by

weiyanwang096
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from machine import Pin, SoftI2C

from ssd1306 import SSD1306_I2C


import time, os

i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=100000)


oled = SSD1306_I2C(128, 64, i2c)
button_up=Pin(4,Pin.IN,Pin.PULL_UP)
button_down=Pin(0,Pin.IN,Pin.PULL_UP)
button_out=Pin(2,Pin.IN,Pin.PULL_UP)
oled.font_load("GB2312-24.fon")
oled.fill(0)
help(oled.font_set)

word_dic={1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l
',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'
x',25:'y',26:'z',27:' '}

def file():
flist = [] #名串列
fstr = '' #名字串
oled.fill(0)
foled_word=0 #file 文字 x 座標
fc_t=0 #file 按的次數
fuw='' #現在使用的文字
oled.text('请输入档案名', 0, 0)
oled.text('~', 0, 21)
oled.show()
while True:
up = button_up.value()
down = button_down.value()
out = button_out.value()
if(up == 0):
fc_t=fc_t+1
if(fc_t > 27):
fc_t = fc_t-27
fuw=word_dic[fc_t]
oled.text(fuw, 120, 50)
oled.show()
time.sleep(0.1)
oled.fill(0)
oled.text('请输入档案名', 0, 0)
oled.text('~', 0, 21)
if(down == 0):
foled_word=foled_word+8
oled.text(fuw, foled_word, 16)
oled.show()
flist.append(fuw)
fc_t=0
time.sleep(0.1)
if(out == 0):
foled_word=0
break
fstr=''.join(flist)
oled.fill(0)
try:
oled.text('读取中...', 0, 0)
oled.show()
file=open('/file/'+fstr+'.txt', 'r') #打開文件
nv = str(file.read()) #讀取文件並存成字串
nv_list = nv.split('@') #用 split 分割成串列
novl = len(nv_list)
except:
oled.fill(0)
time.sleep(1)
oled.text('无法读取', 0, 0)
oled.show()
time.sleep(2)
main()
time.sleep(0.1)
oled.fill(0)
oled.text('读取成功!', 0, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.text('按右键继续',0,0)
oled.show()
c_tr = 0
oled_tim = 0
while True:
oled.fill(0)
up = button_up.value()
down = button_down.value()
out = button_out.value()
if(down == 0):
oled.text(fstr+'.txt', 0, 0)
oled.line(0, 14, 128, 14, 1)
nowy = 16
for i in range(3):
if(oled_tim == novl):
oled_tim = 0
break
nstr = ''
nstr = nv_list[oled_tim]
oled_tim = oled_tim+1
oled.text(nstr, 0, nowy)
oled.show()
nowy = nowy+16
if(up == 0):
oled.text(fstr+'.txt', 0, 0)
oled.line(0, 14, 128, 14, 1)
oled.show()
nowy = 16
if(oled_tim > 4):
oled_tim = oled_tim-6
for i in range(3):
nstr = ''
nstr = nv_list[oled_tim]
oled_tim = oled_tim+1
oled.text(nstr, 0, nowy)
oled.show()
nowy = nowy+16
else:
oled_tim=0
for i in range(3):
nstr = ''
nstr = nv_list[oled_tim]
oled_tim = oled_tim+1
oled.text(nstr, 0, nowy)
oled.show()
nowy = nowy+16
if(out == 0):
time.sleep(0.1)
main()

def sys():
oled.fill(0)
oled.text(' <<Duck System>>', 0, 0)
oled.text('@ version:1.0.0', 0, 16)
oled.text('@ made by:wayne', 0, 26)
oled.show()
while True:
out = button_out.value()
if(out == 0):
break
main()

def main():
oled.fill(0)
mac_t = 0 #main 按鈕點擊次數
oled.text('<<Duck System v1.0>>', 0, 0)
oled.text('1.File(.txt)', 0, 16)
oled.text('2.System', 0, 26)
oled.text('~', 0, 50)
oled.show()
while True:
up = button_up.value()
down = button_down.value()
if(up == 0):
mac_t=mac_t+1
if(mac_t > 2):
mac_t=mac_t-2
oled.text(str(mac_t), 8, 45)
oled.show()
time.sleep(0.1)
oled.fill(0)
oled.text('<<Duck System v1.0>>', 0, 0)
oled.text('1.File(.txt)', 0, 16)
oled.text('2.System', 0, 26)
oled.text('~', 0, 50)
if(down == 0):
oled.text(str(mac_t), 8, 45)
oled.show()
if(mac_t == 1):
file()
if(mac_t == 2):
sys()
time.sleep(0.1)

main()

You might also like