From: Nathaniel Wesley Filardo Date: Tue, 8 Nov 2016 14:57:16 +0000 (-0500) Subject: lamp: GPIO in README, tidy drawings, add 'candle' X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=258d87ace10659ee365547dfd5aad16100645128;p=acmetensortoys-esp-lua_lamp lamp: GPIO in README, tidy drawings, add 'candle' --- diff --git a/README.rst b/README.rst index 69a074a..024932b 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,29 @@ stack the RGB array atop the ESP8266 and hookup via the Doubler's female headers, or do away with the Doubler entirely and hook the male pins on the ESP8266, etc. +ESP IO +###### + +The various boards are interfaced as follows: + ++--------------+----------------------------------------------------------+ +| ESP GPIO Pin | Function | ++--------------+----------------------------------------------------------+ +| 2 | WS2812 serial shift out (to LED array input) | ++--------------+----------------------------------------------------------+ +| 4 | I2C SDA pin (to CAP1188, optional expansion) | ++--------------+----------------------------------------------------------+ +| 5 | I2C SCL pin (to CAP1188, optional expansion) | ++--------------+----------------------------------------------------------+ +| 12 | CAP1188 IRQ (from CAP1188) | ++--------------+----------------------------------------------------------+ +| 14 | CAP1188 RESET (to CAP1188) | ++--------------+----------------------------------------------------------+ + +If GPIO becomes precious, the CAP1188 IRQ and RESET pins could be moved +behind an I2C IO expander as they are low bandwidth. (The expander itself +would presumably merit an IRQ pin and the CAP1188 IRQ could be demuxed.) + Theory of Operation ################### diff --git a/draw-candle.lua b/draw-candle.lua new file mode 100644 index 0000000..00aa7e9 --- /dev/null +++ b/draw-candle.lua @@ -0,0 +1,40 @@ +-- a votive-style candle? +-- +-- 1 2 3 4 5 6 7 8 +-- 00 o o o f f o o o +-- 08 o w o f f o w o +-- 16 o W w w w w W o +-- 24 o W W W W W W o +-- + +return function(t,fb,g,r,b) + fb:fill(0,0,0) + -- static base + local i,v + for i,v in ipairs({18,23,26,27,28,29,30,31}) do fb:set(v,2,2,2) end -- white (W) + for i,v in ipairs({10,15,19,20,21,22}) do fb:set(v,1,1,1) end -- dim white (w) + + local cmax = math.max(r,g,b) + + -- off channels stay off, on channels stay on, just minimally dim + local function adjust(val,bias) if val == 0 then return 0 elseif val <= bias then return 1 else return val - bias end end + -- update many pixels together with the same bias + local function drawbiased(...) + local i,v + local bias = math.random(cmax) + local ag = adjust(g,bias) + local ar = adjust(r,bias) + local ab = adjust(b,bias) + for i,v in ipairs(arg) do fb:set(v,ag,ar,ab) end + end + + -- flame (f) behaviors: equal intensity, dimmer top, dimmer left, and dimmer right + local function draweq() for i,v in ipairs({4,5,12,13}) do fb:set(v,g,r,b) end end + local function drawbb() drawbiased(4,5) end + local function drawlb() drawbiased(4,12) end + local function drawrb() drawbiased(5,13) end + + local ft = { [0] = draweq, draweq, draweq, drawbb, drawlb, drawrb } + t:register(250,tmr.ALARM_AUTO,function() ft[math.random(#ft)]() dodraw() end) + draweq() +end diff --git a/draw-devilish.lua b/draw-devilish.lua index f06fc3e..77921a1 100644 --- a/draw-devilish.lua +++ b/draw-devilish.lua @@ -1,9 +1,12 @@ +-- o x o o x o o x +-- x o o x o o x o +-- x o o o o x x o +-- o x o o x o o x return function(t,fb,g,r,b) - t:unregister() fb:fill(0,0,0) local c = string.char(g,r,b) - fb:set( 2,c) fb:set( 5,c) fb:set( 8,c) fb:set( 9,c) - fb:set( 9,c) fb:set(12,c) fb:set(15,c) fb:set(17,c) - fb:set(17,c) fb:set(22,c) fb:set(23,c) fb:set(26,c) - fb:set(29,c) fb:set(32,c) -end \ No newline at end of file + fb:set( 2,c) fb:set( 5,c) fb:set( 8,c) + fb:set( 9,c) fb:set(12,c) fb:set(15,c) + fb:set(17,c) fb:set(22,c) fb:set(23,c) + fb:set(26,c) fb:set(29,c) fb:set(32,c) +end diff --git a/draw-kiss.lua b/draw-kiss.lua index a9b7660..b4faec1 100644 --- a/draw-kiss.lua +++ b/draw-kiss.lua @@ -1,5 +1,8 @@ +-- 1 0 1 - - - - - +-- 0 x 0 - - x - - +-- 1 0 1 x x - - - +-- - - - - - x - - return function(t,fb,g,r,b) - t:unregister() fb:fill(0,0,0) local ix = 0 local c = string.char(g,r,b) diff --git a/draw-oo.lua b/draw-oo.lua index c7f2a36..d0d6c53 100644 --- a/draw-oo.lua +++ b/draw-oo.lua @@ -1,9 +1,8 @@ return function(t,fb,g,r,b) - t:unregister() fb:fill(0,0,0) local c = string.char(g,r,b) fb:set( 2,c) fb:set( 3,c) fb:set( 6,c) fb:set( 7,c) fb:set( 9,c) fb:set(12,c) fb:set(13,c) fb:set(16,c) fb:set(17,c) fb:set(20,c) fb:set(21,c) fb:set(24,c) fb:set(26,c) fb:set(27,c) fb:set(30,c) fb:set(31,c) - end \ No newline at end of file + end diff --git a/draw-shifty.lua b/draw-shifty.lua index 6de016a..6e4f1f0 100644 --- a/draw-shifty.lua +++ b/draw-shifty.lua @@ -1,5 +1,4 @@ return function(t,fb,g,r,b) - t:unregister() fb:fill(0,0,0) local ix = 0 local c = string.char(g,r,b) @@ -16,4 +15,4 @@ return function(t,fb,g,r,b) ix = 1 - ix dodraw() end) -end \ No newline at end of file +end diff --git a/draw-shifty2.lua b/draw-shifty2.lua index ccbde9e..30f39cf 100644 --- a/draw-shifty2.lua +++ b/draw-shifty2.lua @@ -1,5 +1,4 @@ -return function(t,fb,g,r,b) - t:unregister() +return function(t,fb,g,r,b) fb:fill(0,0,0) local ix = 0 local c = string.char(g,r,b) @@ -19,4 +18,4 @@ return function(t,fb,g,r,b) ix = 1 - ix dodraw() end) - end \ No newline at end of file + end diff --git a/draw-snake2.lua b/draw-snake2.lua index 8043f0c..95dd678 100644 --- a/draw-snake2.lua +++ b/draw-snake2.lua @@ -3,8 +3,8 @@ -- 1 2 3 4 5 6 7 8 -- 00 o o o o o h x h -- 08 o o o o o e x o --- 16 o o w w o o x o --- 24 x x w w x x x o +-- 16 w w w w o o x o +-- 24 w w w w x x x o -- return function(t,fb,g,r,b) local ix = 2 -- since we start effectively in state 1... @@ -23,9 +23,9 @@ return function(t,fb,g,r,b) , [5] = function() fb:set(20,c) fb:set(28,0,0,0) end -- slither 2 , [6] = function() fb:set(19,c) fb:set(20,0,0,0) fb:set(27,0,0,0) fb:set(28,c) end - -- slither 1, heart off + -- slither 3, heart off , [7] = function() fb:set(18,c) fb:set(19,0,0,0) fb:set(20,c) fb:set(26,0,0,0) fb:set(27,c) fb:set(28,0,0,0) fb:set(14,0,0,0) end - -- slither 2 + -- slither 4 , [8] = function() fb:set(17,c) fb:set(18,0,0,0) fb:set(19,c) fb:set(20,0,0,0) fb:set(25,0,0,0) fb:set(26,c) fb:set(27,0,0,0) fb:set(28,c) end } fb:fill(0,0,0)