lcd.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --- 模块功能:LCD适配
  2. require "ILI9341"
  3. module(..., package.seeall)
  4. -- 设置字体大小
  5. disp.setfontheight(32)
  6. -- LCD分辨率的宽度和高度(单位是像素)
  7. WIDTH, HEIGHT, BPP = disp.getlcdinfo()
  8. -- 1个ASCII字符宽度为8像素,高度为16像素;汉字宽度和高度都为16像素
  9. CHAR_WIDTH = 16
  10. --[[
  11. 函数名:getxpos
  12. 功能 :计算字符串居中显示的X坐标
  13. 参数 :
  14. str:string类型,要显示的字符串
  15. 返回值:X坐标
  16. ]]
  17. function getxpos(str)
  18. return (WIDTH - string.len(str) * CHAR_WIDTH) / 2
  19. end
  20. function setcolor(color)
  21. if BPP ~= 1 then
  22. return disp.setcolor(color)
  23. end
  24. end
  25. function SetBackPin()
  26. pmd.ldoset(15, pmd.LDO_VLCD)
  27. setOutputFnc = pins.setup(pio.P0_19, 0)
  28. setOutputFnc(1)
  29. end
  30. SetBackPin()
  31. sys.timerStart(SetBackPin, 100) -- 开机启动背光
  32. -- SetLedPin()
  33. -- sys.timerStart(SetLedPin, 100) -- 开机启动背光
  34. sys.taskInit(function()
  35. -- 定义照片文件路径列表
  36. local photo_list = {
  37. "/lua/Calling.jpg",
  38. "/lua/PowerOn.jpg",
  39. "/lua/PutInSerNum.jpg",
  40. -- 你可以根据需要添加更多照片路径
  41. }
  42. local photo_index = 1
  43. while true do
  44. disp.clear()
  45. print("显示照片")
  46. -- 获取当前要显示的照片路径
  47. local photo_path = photo_list[photo_index]
  48. if photo_path then
  49. disp.putimage(photo_path, 0, 0)
  50. else
  51. print("未找到对应的照片路径")
  52. end
  53. -- 更新显示窗口
  54. getxpos("Hello World ----------------------------")
  55. disp.update()
  56. print("照片显示完成")
  57. -- 切换到下一张照片
  58. photo_index = photo_index + 1
  59. if photo_index > #photo_list then
  60. photo_index = 1
  61. end
  62. -- 等待 10 秒
  63. sys.wait(10000)
  64. end
  65. end)