forked from freyssin/elmis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.lua
54 lines (42 loc) · 1.03 KB
/
led.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- LGPL v3 License (Free Software Foundation)
-- Copyright (C) 2017 - 2018 ScalAgent Distributed Technologies
-- Play with blue led on board (Wemos or ESP8266)
local LED = {}
local dev, publish
-- Led shield parameters
local delay=1000
local pin_led = 4 -- GPIO 2 Blue led
local lighton = gpio.HIGH
-- Declare module functions below
local function toggle()
if lighton == gpio.LOW then
lighton = gpio.HIGH
else
lighton = gpio.LOW
end
gpio.write(pin_led, lighton)
end
local function blink()
toggle()
tmr.create():alarm(delay, tmr.ALARM_SINGLE, toggle)
end
-- Initialisation function
local function init(d, p)
dev = d
publish = p
-- Initializes the shield
gpio.mode(pin_led, gpio.OUTPUT)
gpio.write(pin_led, lighton)
end
-- Table of functions
local actions = {
["toggle"] = toggle,
["blink"] = blink
}
-- These 2 methods are needed by micro-service framework
LED.init = init
LED.actions = actions
-- These methods are only needed for external use of the LED module
LED.toggle = toggle
LED.blink = blink
return LED