This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Activation after holding a button
#1
Is there a way that I press a button for 3-4 seconds only then it sends a command "0" or "1"? thanks Rolleyes
Reply
#2
https://kb.logicmachine.net/scripting/short-long-press/
------------------------------
Ctrl+F5
Reply
#3
thank you Hello, I only need to send a value of 0 (OFF) when pressed for 3-4 seconds (a short press does nothing). What should I refer to in the script? thanks
Reply
#4
Try this (not tested)
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
if not client then   timeout = 1 -- long press in seconds   mapping = {     ['32/1/1'] = { short = '32/1/2', long = '32/1/3' },     ['32/1/4'] = { short = '32/1/5', long = '32/1/6' },   }   timerstep = timeout / 4   function eventhandler(event)     local object = mapping[ event.dst ]     if not object then       return     end     local value = busdatatype.decode(event.datahex, dt.bool)     if value then       object.timer = timeout     elseif object.timer then       object.timer = nil      -- grp.write(object.short, not grp.getvalue(object.short), dt.bool)     end   end   client = require('localbus').new(1)   clientfd = socket.fdmaskset(client:getfd(), 'r')   client:sethandler('groupwrite', eventhandler)   timer = require('timerfd').new(timerstep)   timerfd = socket.fdmaskset(timer:getfd(), 'r') end res, clientstat, timerstat = socket.selectfds(10, clientfd, timerfd) if clientstat then   client:step() end if timerstat then   timer:read()   for addr, object in pairs(mapping) do     if object.timer then       object.timer = object.timer - timerstep       if object.timer <= 0 then         object.timer = nil         grp.write(object.long, false, dt.bool)       end     end   end end
------------------------------
Ctrl+F5
Reply


Forum Jump: