led-stick.lua 755 B

12345678910111213141516171819202122232425262728293031
  1. return function (connection, req, args)
  2. local pin, w, h, offset = 1, 140, 28, 0
  3. if connection ~= nil then
  4. dofile('httpserver-header.lc')(connection, 200, 'html')
  5. end
  6. gpio.mode(pin, gpio.INT)
  7. local function pin1cb(level)
  8. print(level)
  9. file.open('led-stick.dat', 'r')
  10. if level == 1 then
  11. offset = 0
  12. while offset < w do
  13. file.seek("set", (offset * h) * 3)
  14. ws2812.write(file.read(h * 3))
  15. offset = offset + 1
  16. end
  17. else
  18. offset = w - 1
  19. while offset >= 0 do
  20. file.seek("set", (offset * h) * 3)
  21. ws2812.write(file.read(h * 3))
  22. offset = offset - 1
  23. end
  24. end
  25. file.close()
  26. ws2812.write(string.char(0):rep(h * 3))
  27. end
  28. gpio.trig(pin, 'both', pin1cb)
  29. end