ESP-01 capacitive touch sensor
Posted: Tue Jun 23, 2015 11:41 am
Hi,
I've designed a capacitive touch on ESP-01 and I hope that you enjoy it!
Here is the LUA code:
local send_pin = 4 --GPIO2
local float_pin = 3 --GPIO0
gpio.mode(send_pin,gpio.OUTPUT)
gpio.mode(float_pin,gpio.INT)
counter = 0
comanda = 0
function print_comanda()
tmr.alarm(0, 500, 0, function()
print("comanda = ", comanda)
comanda = 0
end)
end
function incr_comanda()
tmr.alarm(1, 50, 0, function()
if counter > 3 then
comanda = comanda + 1
counter = 0
tmr.stop(1)
end
end)
end
function test()
if gpio.read(float_pin) == gpio.HIGH then
counter = counter + 1
incr_comanda()
print_comanda()
end
end
pwm.setup(send_pin, 1000, 512)
pwm.start(send_pin)
gpio.trig(float_pin,"both",test)
I put a 800kohm resistor between send_pin and foiled float_pin and it works.
I've designed a capacitive touch on ESP-01 and I hope that you enjoy it!
Here is the LUA code:
local send_pin = 4 --GPIO2
local float_pin = 3 --GPIO0
gpio.mode(send_pin,gpio.OUTPUT)
gpio.mode(float_pin,gpio.INT)
counter = 0
comanda = 0
function print_comanda()
tmr.alarm(0, 500, 0, function()
print("comanda = ", comanda)
comanda = 0
end)
end
function incr_comanda()
tmr.alarm(1, 50, 0, function()
if counter > 3 then
comanda = comanda + 1
counter = 0
tmr.stop(1)
end
end)
end
function test()
if gpio.read(float_pin) == gpio.HIGH then
counter = counter + 1
incr_comanda()
print_comanda()
end
end
pwm.setup(send_pin, 1000, 512)
pwm.start(send_pin)
gpio.trig(float_pin,"both",test)
I put a 800kohm resistor between send_pin and foiled float_pin and it works.