矿石收音机论坛

 找回密码
 加入会员

QQ登录

只需一步,快速开始

搜索
查看: 397|回复: 0

esp32制作电子表micropython代码求解

[复制链接]
     
发表于 2025-3-9 23:59:19 | 显示全部楼层 |阅读模式
拟diy一个esp32驱动的家用4位电子表,
好友帮我写了一个代码(见下)
原来是在esp32-s2上运行正常的,
被我移植到esp32早期版(见下图)
然后就不正常了。

在此向玩micropython的高手请教:
注释一下,下面代码的意思。
先谢谢啦!


  1. from machine import Pin, I2C
  2. import ssd1306
  3. i2c = I2C(1)
  4. oled = ssd1306.SSD1306_I2C(128, 32, i2c)
  5. import st7735s8 as st
  6. import st7735s11 as st1
  7. import st7735s10 as st2
  8. import st7735s9 as st3
  9. from machine import SPI,PWM
  10. import time

  11. spi=SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13))
  12. #spi = SPI(2,baudrate=20000000)
  13. lcd=st.ST7735S(spi,dc=16,rst=17,cs=18,bl=32,width=128,height=160)
  14. lcd.rotate(180)
  15. lcd1=st1.ST7735S(spi,dc=16,rst=17,cs=19,bl=32,width=128,height=160)
  16. lcd1.rotate(180)
  17. lcd2=st2.ST7735S(spi,dc=16,rst=17,cs=25,bl=32,width=128,height=160)
  18. lcd2.rotate(180)
  19. lcd3=st3.ST7735S(spi,dc=16,rst=17,cs=26,bl=32,width=128,height=160)
  20. lcd3.rotate(180)

  21. pwm1 = PWM(Pin(32), freq=1000, duty=256)

  22. import pwm
  23. import network
  24. wlan = network.WLAN(network.STA_IF)
  25. wlan.active(True)

  26. from machine import RTC
  27. rtc = RTC()

  28. pwm.nettime_set()
  29. rtc.datetime()
  30. print(rtc.datetime())
  31. ttt=pwm.t()

  32. qc=0
  33. qqc=0
  34. qqqc=0

  35. while True:
  36.     datetime=rtc.datetime()
  37.     if datetime[6]!=qqqc:
  38.         qqc=0
  39.     if datetime[5] ==1 and datetime[6] ==59 :
  40.         qc=0
  41.     if  datetime[5] == 0  and datetime[6]==1 and qc==0:
  42.         pwm.nettime_set()
  43.         qc+=1
  44.     if qqc==0:
  45.         ttt=pwm.t()
  46.         qqqc=datetime[6]
  47.     lcd.clear()
  48.     lcd.drawText3('A6',str(ttt[4]%10),0,0,st.rgb565(255,255,0))#
  49.     lcd.show()
  50.     lcd1.clear()
  51.     lcd1.drawText3('A6',str(ttt[4]//10),0,0,st.rgb565(0,255,0))#
  52.     lcd1.show()
  53.     lcd2.clear()
  54.     lcd2.drawText3('A6',str(ttt[3]%10),0,0,st.rgb565(0,0,255))#时个位
  55.     lcd2.show()
  56.     lcd3.clear()
  57.     lcd3.drawText3('A6',str(ttt[3]//10),0,0,st.rgb565(255,0,0))#时十位
  58.     lcd3.show()
  59.    
  60.     if ttt[5]/2==ttt[5]//2:
  61.         oled.fill(0)
  62.         oled.fill_rect(32,12,12,12,1)
  63.         oled.fill_rect(92,12,12,12,1)
  64.         oled.show()
  65.     else:
  66.         oled.fill(0)
  67.         oled.fill_rect(32,12,12,12,0)
  68.         oled.fill_rect(92,12,12,12,0)
  69.         oled.show()
  70.     qqc=1
复制代码



我现在的esp32板子:
引脚1.jpg
您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

小黑屋|手机版|矿石收音机 ( 蒙ICP备05000029号-1 )

蒙公网安备 15040402000005号

GMT+8, 2025-4-29 11:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表