-- 7 Segment Display for MCP23008 by John Longworth December 2017 -- Using pins 3 & 4 to be compatible with ESP001 -- 7 segment digit 1 = b + c = 64 + 32 = 96 (0x60) -- 7 segment digit 2 = abdeg = 128+64+16+8+2 = 218 (0xDA)... -- DP = 1 added to display to show decimal point -- Uses mcp23008.lua - This file must be in the ESP8266 memory nums = {0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6,0xFC} -- 1, 2 ...0 local i = 1 mcp = require ("mcp23008") id = 0x00 -- Always 0 sda = 3 -- GPIO0 Connect to Pin 2 of MCP23008 scl = 4 -- GPIO2 Connect to Pin 1 of MCP23008 mcp.begin(id,sda,scl,i2c.SLOW) mcp.writeIODIR(0x00) -- Set all GPIO pins as outputs tmr.alarm(0,500,1,function() local segs = nums[i] if (i % 2 == 1) then -- Toggle decimal point segs = segs + 1 end mcp.writeGPIO(segs) print(segs) i = i + 1 if (i > 10) then i = 1 end end)