-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathdetectpush.lua
More file actions
48 lines (42 loc) · 1.5 KB
/
detectpush.lua
File metadata and controls
48 lines (42 loc) · 1.5 KB
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
--[[
Detect push button
This example detects a push button connected to pin 4 and sends the command
to the printer screen when the button is pressed.
The push button is connected to pin 4 and the LOW value is when the button
is pressed.
Put this script in the ESP3D flash file system and call it from the init script in
configuration.h.
#define ESP_AUTOSTART_SCRIPT "[ESP300]/FS/detectpush.lua"
You can also start it manually from the serial monitor by typing:
[ESP300]/FS/detectpush.lua
Be sure to have the following line comment out in the configure.h:
#define ESP_LUA_INTERPRETER_FEATURE
]]--
-- Setup
-- pin 0 is connected to the push button
local pin = 0
-- LOW is the value when the button is pressed
local trigger_value = LOW
-- send ESP3D command to display current IP address to the printer screen
local command = "[ESP212]IP:%ESP_IP%\n"
-- variable to read the pin value
local pinval
local lastpush = millis()
-- define the pin mode
pinMode(pin, INPUT_PULLUP)
-- Main loop
while (true) do
-- read the pin value
pinval = digitalRead(pin)
-- if the pin value is `trigger_value` then send the command
if (pinval == trigger_value) then
-- do not overflow the system so only send command if at least 1 second elapsed since last one
if ((millis()-lastpush) > 1000) then
lastpush = millis()
-- send the command to the esp3d
print(command)
end
end
-- yield to other tasks
yield()
end