3698浏览
查看: 3698|回复: 9

[求助] 掌控板2.2.0的自带程序

[复制链接]
掌控板2.2.0里面有自带程序,可是如何获取自带的程序?求助大佬回答

qrm  初级技匠

发表于 2023-4-15 22:20:29

是出场默认的那个程序吗?mind+中打开文件系统,那个main.py应该就是了
回复

使用道具 举报

快看擎天猪  中级技师
 楼主|

发表于 2023-4-21 20:29:29

qrm 发表于 2023-4-15 22:20
是出场默认的那个程序吗?mind+中打开文件系统,那个main.py应该就是了

好的谢谢
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-6-9 15:14:06

那个main.py程序是转到mpythondemo。
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-6-9 15:15:11

代码我复制一下:
  1. #mPythonType:0
  2. # # exec(open('./mPythonFactorytest_2_0.py').read(),globals())
  3. # exec(open('./mPythonDemo.py').read(),globals())
  4. # Flappy Bird game for mPython
  5. # frok from github.com/zelacerda/micropython ,2017 - by zelacerda
  6. # modify from LabPlus@Tangliufeng
  7. import ntptime
  8. from mpython import*
  9. from machine import Timer,RTC
  10. import _thread
  11. from random import randint
  12. from math import sin, cos
  13. have_magnetics = True if 48 in i2c.scan() else False
  14. data=(2018, 12, 15, 6, 8,30, 0, 0)
  15. RTC().datetime(data)
  16. clock=Clock(oled,64,32,30)
  17. mode=0
  18. modeNum=5
  19. if have_magnetics: modeNum+=1
  20. Center_x=63
  21. Center_y=31
  22. # 绘制罗盘中心坐标和半径
  23. xc,yc,comp_r= 64,32,30
  24. is_calibrate = False
  25. def draw_heading(angle):
  26.     """绘制磁北指针"""
  27.     global xc,yc,comp_r
  28.     angle = 360 - angle
  29.     am = math.pi * 2.0 * angle / 360
  30.     xm = round(xc + comp_r * math.sin(am))
  31.     ym = round(yc - comp_r * math.cos(am))
  32.     oled.line(xc, yc, xm, ym, 1)
  33. def scanBtnThread(_):
  34.     global mode
  35.     aState=0
  36.     bState=0
  37.     lastaState =0
  38.     lastbState =0
  39.     while True:
  40.         try:
  41.             aState=button_a.value()
  42.             bState=button_b.value()
  43.             if aState!=lastaState:
  44.                 sleep_ms(20)
  45.                 if aState==0:
  46.                     mode=mode-1
  47.                     mode=mode % modeNum
  48.                     print("mode:%d" %mode)
  49.                 lastaState=aState
  50.             if bState!=lastbState:
  51.                 sleep_ms(20)
  52.                 if bState==0:
  53.                     mode=mode+1
  54.                     mode=mode % modeNum
  55.                     print("mode:%d" %mode)
  56.                 lastbState=bState
  57.         except KeyboardInterrupt:
  58.             _thread.exit()
  59.             # break
  60. _thread.start_new_thread(scanBtnThread,(1,))
  61.    
  62. def Refresh(_):
  63.     if mode ==0:
  64.         oled.DispChar("钟表",0,0)
  65.         clock.settime()
  66.         clock.drawClock()
  67.         oled.show()
  68.         oled.fill(0)
  69. tim1 = Timer(1)
  70. tim1.init(period=1000, mode=Timer.PERIODIC, callback=Refresh)
  71. class snow():
  72.     def __init__(self):
  73.         self.x = randint(0,127)         #随机生成雪花的起始坐标点
  74.         self.y = randint(0,10)
  75.         self.r = randint(1,2)           #随机生成雪花的半径大小
  76.         self.vx = randint(-2,2)         #随机生成雪花的x,y移动路径
  77.         self.vy = randint(1,3)
  78.     def refresh(self):
  79.         self.x += self.vx               #下移坐标,雪花落下
  80.         self.y += self.vy
  81.         if self.x > 128 or self.x < 0:
  82.             self.x = randint(0,127)
  83.         if self.y > 63 or self.y < 0:
  84.             self.y = 0
  85.     def run(self):
  86.             self.refresh()
  87.             oled.fill_circle(self.x,self.y,self.r,1)     #画雪花
  88. balls = []
  89. for x in range(20):              #生成20个雪花点
  90.     balls.append(snow())
  91. import music                        # 导入music模块
  92. note=["C4:2","D4:2","E4:2","F4:2","G4:2","A4:2","B4:2"]     # 定义7音阶的元组
  93. pStatus,yStatus,tStatus,hStatus,oStatus,nStatus,p0Status=[1]*7  # 按键状态标记变量
  94. p0 = TouchPad(Pin(33))              # 由于掌控板上的触摸按键只有6个,还需拓展多一个引脚P0,对应ESP32的IO33
  95. def drawPiano(x,y,w,h,num):
  96.     if num==0:
  97.         for i in range(7):
  98.             oled.rect((x+i*w),y,w,h,1)
  99.     else:
  100.         oled.fill_rect((x+(num-1)*w),y,w,h,1)
  101. X = const(64)
  102. Y = const(32)
  103. f = [[0.0 for _ in range(3)] for _ in range(8)]
  104. cube = ((-20,-20, 20), (20,-20, 20), (20,20, 20), (-20,20, 20),
  105.         (-20,-20,-20), (20,-20,-20), (20,20,-20), (-20,20,-20))
  106. while True:
  107.     if mode ==1:
  108.         oled.text("level",0,0)
  109.         x=accelerometer.get_x()
  110.         y=accelerometer.get_y()
  111.         if y<=1 and y>=-1:
  112.             offsetX=int(numberMap(y,1,-1,-64,64))
  113.         if x<=1 and x>=-1:
  114.             offsetY=int(numberMap(x,1,-1,32,-32))
  115.         move_x=Center_x+offsetX
  116.         move_y=Center_y+offsetY
  117.         oled.circle(Center_x,Center_y,6,1)
  118.         oled.fill_circle(move_x,move_y,4,1)
  119.         oled.text("%0.1f,%0.1f" %(x,y),60,0)
  120.         if offsetX==0 and offsetY==0:
  121.             rgb.fill((0,10,0))
  122.             rgb.write()
  123.         else:
  124.             rgb.fill((0,0,0))
  125.             rgb.write()
  126.         oled.show()
  127.         oled.fill(0)
  128.     if mode ==2:
  129.         oled.DispChar("钢琴",0,0)
  130.         drawPiano(28,20,10,35,0)
  131.         if touchPad_P.read()<100 and pStatus==1:      # 检测按键按下和判断按键标记
  132.             music.play(note[0],wait=False)                       # 播放音符
  133.             drawPiano(28,20,10,35,1)
  134.             pStatus=0                                 # 按键标记置0
  135.         elif touchPad_P.read()>=100:
  136.             pStatus=1
  137.         if touchPad_Y.read()<100 and yStatus==1:
  138.             music.play(note[1],wait=False)
  139.             drawPiano(28,20,10,35,2)
  140.             yStatus=0
  141.         elif touchPad_Y.read()>=100:
  142.             yStatus=1
  143.         if touchPad_T.read()<100 and tStatus==1:
  144.             music.play(note[2],wait=False)
  145.             drawPiano(28,20,10,35,3)
  146.             tStatus=0
  147.         elif touchPad_T.read()>=100:
  148.             tStatus=1
  149.         if touchPad_H.read()<100 and hStatus==1:
  150.             music.play(note[3],wait=False)
  151.             drawPiano(28,20,10,35,4)
  152.             hStatus=0
  153.         elif touchPad_H.read()>=100:
  154.             hStatus=1
  155.         if touchPad_O.read()<100 and oStatus==1:
  156.             music.play(note[4],wait=False)
  157.             drawPiano(28,20,10,35,5)
  158.             oStatus=0
  159.         elif touchPad_O.read()>=100:
  160.             oStatus=1
  161.         if touchPad_N.read()<100 and nStatus==1:
  162.             music.play(note[5],wait=False)
  163.             drawPiano(28,20,10,35,6)
  164.             nStatus=0
  165.         elif touchPad_N.read()>=100:
  166.             nStatus=1
  167.         if p0.read()<100 and p0Status==1:
  168.             music.play(note[6],wait=False)
  169.             drawPiano(28,20,10,35,7)
  170.             p0Status=0
  171.         elif p0.read()>=100:
  172.             p0Status=1
  173.         oled.show()
  174.         oled.fill(0)
  175.     if mode ==3:
  176.         oled.DispChar("飘雪",0,0)
  177.         for b in balls:              #雪花落下
  178.             b.run()
  179.         oled.show()                  #显示oled
  180.         oled.fill(0)                 #清屏
  181.         sleep_ms(50)                 #刷新时间
  182.     if mode ==4:
  183.         prevmode=mode
  184.         for angle in range(0, 361, 5):  # 0 to 360 deg 3step
  185.             if prevmode !=mode:
  186.                 break
  187.             for i in range(8):
  188.                 r  = angle * 0.0174532  # 1 degree
  189.                 x1 = cube[i][2] * sin(r) + cube[i][0] * cos(r)  # rotate Y
  190.                 ya = cube[i][1]
  191.                 z1 = cube[i][2] * cos(r) - cube[i][0] * sin(r)
  192.                 x2 = x1
  193.                 y2 = ya * cos(r) - z1 * sin(r)  # rotate X
  194.                 z2 = ya * sin(r) + z1 * cos(r)
  195.                 x3 = x2 * cos(r) - y2 * sin(r)  # rotate Z
  196.                 y3 = x2 * sin(r) + y2 * cos(r)
  197.                 z3 = z2
  198.                 x3 = x3 + X
  199.                 y3 = y3 + Y
  200.                 f[i][0] = x3  # store new values
  201.                 f[i][1] = y3
  202.                 f[i][2] = z3
  203.            
  204.             oled.line(int(f[0][0]), int(f[0][1]), int(f[1][0]), int(f[1][1]), 1)
  205.             oled.line(int(f[1][0]), int(f[1][1]), int(f[2][0]), int(f[2][1]), 1)
  206.             oled.line(int(f[2][0]), int(f[2][1]), int(f[3][0]), int(f[3][1]), 1)
  207.             oled.line(int(f[3][0]), int(f[3][1]), int(f[0][0]), int(f[0][1]), 1)
  208.             oled.line(int(f[4][0]), int(f[4][1]), int(f[5][0]), int(f[5][1]), 1)
  209.             oled.line(int(f[5][0]), int(f[5][1]), int(f[6][0]), int(f[6][1]), 1)
  210.             oled.line(int(f[6][0]), int(f[6][1]), int(f[7][0]), int(f[7][1]), 1)
  211.             oled.line(int(f[7][0]), int(f[7][1]), int(f[4][0]), int(f[4][1]), 1)
  212.             oled.line(int(f[0][0]), int(f[0][1]), int(f[4][0]), int(f[4][1]), 1)
  213.             oled.line(int(f[1][0]), int(f[1][1]), int(f[5][0]), int(f[5][1]), 1)
  214.             oled.line(int(f[2][0]), int(f[2][1]), int(f[6][0]), int(f[6][1]), 1)
  215.             oled.line(int(f[3][0]), int(f[3][1]), int(f[7][0]), int(f[7][1]), 1)
  216.             oled.line(int(f[1][0]), int(f[1][1]), int(f[3][0]), int(f[3][1]), 1)  # cross
  217.             oled.line(int(f[0][0]), int(f[0][1]), int(f[2][0]), int(f[2][1]), 1)  # cross
  218.             oled.DispChar('3D cube', 0, 0)
  219.             oled.show()  # display
  220.             oled.fill(0)  # clear
  221.     if mode == 5 and have_magnetics:
  222.         prevmode=mode
  223.         oled.DispChar('指北针',0,0)
  224.         # 电子罗盘校准
  225.         if not is_calibrate:
  226.             magnetic.calibrate()
  227.             is_calibrate =True
  228.         # sleep(2)
  229.         oled.DispChar('指北针',0,0)
  230.         # 绘制罗盘轮廓
  231.         oled.circle(xc, yc, comp_r+1, 1)
  232.         oled.show()
  233.         while True:
  234.             if prevmode !=mode:
  235.                 oled.fill(0)
  236.                 break
  237.                 # 获取磁力计电子罗盘角度
  238.             angle = magnetic.get_heading()
  239.             # 清除指针
  240.             oled.fill_circle(xc, yc, comp_r, 0)
  241.             oled.fill_rect(95,0,30,16,0)
  242.             # 显示罗盘指针
  243.             draw_heading(angle)
  244.             oled.text("d" %angle,95,0)
  245.             oled.show()
  246.             print("磁北极夹角: %d" %angle)
  247.             
复制代码
回复

使用道具 举报

快看擎天猪  中级技师
 楼主|

发表于 2023-6-10 22:36:19


哦!谢谢了!
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-6-27 11:02:39


不用谢。
回复

使用道具 举报

三春牛-创客  初级技神

发表于 2023-6-27 11:03:51


之前我看掌控板文件时找到的
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-7-20 22:38:17

mpythondemo程序。
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-7-20 22:39:19

这里面的知识还挺多的。研究了好久……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail