aboutsummaryrefslogtreecommitdiff
path: root/oled.lua
diff options
context:
space:
mode:
Diffstat (limited to 'oled.lua')
-rw-r--r--oled.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/oled.lua b/oled.lua
new file mode 100644
index 0000000..90bcf47
--- /dev/null
+++ b/oled.lua
@@ -0,0 +1,33 @@
+local oled = {}
+
+local disp
+
+function oled.init()
+ i2c.setup(0, 2, 1, i2c.SLOW)
+ disp = u8g.ssd1306_128x32_i2c(0x3c)
+ disp:setContrast(0)
+ oled.cmd{0xd9, 0x21}
+end
+
+function oled.update(func)
+ local function drawPages()
+ func(disp)
+ if disp:nextPage() then
+ node.task.post(drawPages)
+ end
+ end
+ disp:firstPage()
+ node.task.post(drawPages)
+end
+
+function oled.cmd(t)
+ i2c.start(0)
+ i2c.address(0, 0x3c, i2c.TRANSMITTER)
+ i2c.write(0, 0)
+ for i, v in ipairs(t) do
+ i2c.write(0, v)
+ end
+ i2c.stop(0)
+end
+
+return oled