]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
lamp: GPIO in README, tidy drawings, add 'candle'
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Tue, 8 Nov 2016 14:57:16 +0000 (09:57 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Tue, 8 Nov 2016 14:57:16 +0000 (09:57 -0500)
README.rst
draw-candle.lua [new file with mode: 0644]
draw-devilish.lua
draw-kiss.lua
draw-oo.lua
draw-shifty.lua
draw-shifty2.lua
draw-snake2.lua

index 69a074ac293f30ef1a5e21172e540ecf996f3ed1..024932bbee6aee99240d2229248b849fb67e795f 100644 (file)
@@ -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 (file)
index 0000000..00aa7e9
--- /dev/null
@@ -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
index f06fc3e7ca111822b2a3b4a9e9988299a68dcc82..77921a10912af7c39e57f52766a5d0b3b4d297aa 100644 (file)
@@ -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
index a9b7660b06fe61c19130fb08dbb2908913df02a4..b4faec10169887152bfcccd083c9cfd50e1dc8bd 100644 (file)
@@ -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)
index c7f2a36ffce34b58d5e539618815c2b8ec4eadf7..d0d6c53d4cae491a4e1a47e1dd14301ab4eeea74 100644 (file)
@@ -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
index 6de016ad592dd921d57b10f9934481d2d00319e0..6e4f1f0f3f040299a1900dc80467488ff2190327 100644 (file)
@@ -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
index ccbde9e28ab0ccae5bac579278c13da04cbd6b85..30f39cf9e819e9e1321b5eefe4f8c3d37998444f 100644 (file)
@@ -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
index 8043f0c5c9c8d47ea4f5083d6f1c2b5a91ca49fe..95dd678a8823a04ee4b3bc7b2c845f8521a4c013 100644 (file)
@@ -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)