{"action":"created","issue":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/790","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/790/labels{/name}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/790/comments","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/790/events","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/790","id":118710771,"number":790,"title":"ws2812 buffer","user":{"login":"Alkorin","id":388530,"avatar_url":"https://avatars.githubusercontent.com/u/388530?v=3","gravatar_id":"","url":"https://api.github.com/users/Alkorin","html_url":"https://github.com/Alkorin","followers_url":"https://api.github.com/users/Alkorin/followers","following_url":"https://api.github.com/users/Alkorin/following{/other_user}","gists_url":"https://api.github.com/users/Alkorin/gists{/gist_id}","starred_url":"https://api.github.com/users/Alkorin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alkorin/subscriptions","organizations_url":"https://api.github.com/users/Alkorin/orgs","repos_url":"https://api.github.com/users/Alkorin/repos","events_url":"https://api.github.com/users/Alkorin/events{/privacy}","received_events_url":"https://api.github.com/users/Alkorin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-24T21:50:55Z","updated_at":"2015-11-29T13:37:22Z","closed_at":null,"body":"Dunno if it's only me, but coming from C, playing with immutable strings with the ws2812 library is painful: when you have a long strip of leds, it's easier to have a buffer which represent your current strip and be able to set any byte in it.\r\n\r\nI've written a PoC (my first hack with a lua library...) of a such buffer:\r\nhttps://github.com/Alkorin/nodemcu-firmware/compare/dev...Alkorin:ws2812-buffer\r\n\r\nCurrent API:\r\n```\r\nbuffer = ws2812.newBuffer(nbLeds)\r\nws2812.setBuffer(buffer, led, G, R, B)\r\nws2812.writeBuffer(pin, buffer)\r\n```\r\n\r\nNext step, be able to call set on the buffer and have:\r\n```\r\nbuffer = ws2812.newBuffer(nbLeds)\r\nbuffer.set(led, G, R, B)\r\nws2812.writeBuffer(pin, buffer)\r\n```\r\n\r\nAny advice are welcome :)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments/160416977","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/790#issuecomment-160416977","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/790","id":160416977,"user":{"login":"Alkorin","id":388530,"avatar_url":"https://avatars.githubusercontent.com/u/388530?v=3","gravatar_id":"","url":"https://api.github.com/users/Alkorin","html_url":"https://github.com/Alkorin","followers_url":"https://api.github.com/users/Alkorin/followers","following_url":"https://api.github.com/users/Alkorin/following{/other_user}","gists_url":"https://api.github.com/users/Alkorin/gists{/gist_id}","starred_url":"https://api.github.com/users/Alkorin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alkorin/subscriptions","organizations_url":"https://api.github.com/users/Alkorin/orgs","repos_url":"https://api.github.com/users/Alkorin/repos","events_url":"https://api.github.com/users/Alkorin/events{/privacy}","received_events_url":"https://api.github.com/users/Alkorin/received_events","type":"User","site_admin":false},"created_at":"2015-11-29T13:37:22Z","updated_at":"2015-11-29T13:37:22Z","body":"@TerryE write method added as well as a getter.\r\n\r\nFading led chaser:\r\n```lua\r\nlocal i, a = 0, ws2812.newBuffer(16); a:fill(0,0,0); tmr.alarm(0, 100, 1, function()\r\n        for i = 0, (a:size()-1) do\r\n                g, r, b = a:get(i)\r\n                a:set(i, g/2, r/2, b/2)\r\n        end\r\n        i=i+1\r\n        a:set(i%a:size(), 0, 255, 0)\r\n        a:write(4)\r\nend)\r\n```\r\n\r\nWill now fix metatables"}}