HelloWorld.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. local disp
  2. -- setup SPI and connect display
  3. local function init_spi_display()
  4. -- Hardware SPI CLK = GPIO14
  5. -- Hardware SPI MOSI = GPIO13
  6. -- Hardware SPI MISO = GPIO12 (not used)
  7. -- Hardware SPI /CS = GPIO15 (not used)
  8. -- CS, D/C, and RES can be assigned freely to available GPIOs
  9. local cs = 8 -- GPIO15, pull-down 10k to GND
  10. local dc = 4 -- GPIO2
  11. local res = 0 -- GPIO16
  12. local bus = 1
  13. spi.setup(bus, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
  14. -- we won't be using the HSPI /CS line, so disable it again
  15. gpio.mode(8, gpio.INPUT, gpio.PULLUP)
  16. -- initialize the matching driver for your display
  17. -- see app/include/ucg_config.h
  18. --disp = ucg.ili9341_18x240x320_hw_spi(bus, cs, dc, res)
  19. disp = ucg.st7735_18x128x160_hw_spi(bus, cs, dc, res)
  20. end
  21. do
  22. init_spi_display()
  23. disp:begin(ucg.FONT_MODE_TRANSPARENT)
  24. disp:clearScreen()
  25. disp:setFont(ucg.font_ncenR12_tr);
  26. disp:setColor(255, 255, 255);
  27. disp:setColor(1, 255, 0,0);
  28. disp:setPrintPos(0, 25)
  29. disp:print("Hello World!")
  30. end