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.

Deactivate button
#1
HI to all

I want to press a button in LogicMachine and then for a predefined time, pushing the button for a second, third or fourth time to not activate it.

Example.

First time: Push button 1 (do something and start counting 1 min)
Second time (after 20 sec): Push button 1 do nothing   
Third time (after 30 sec): Push button 1 do nothing   
Fourth time (after 50 sec): Push button 1 do nothing   
Fifth time (after 1min and 10 sec): Push button 1 do again something.

Do you have any identical script?

Thanks for you cooperation! 
Reply
#2
Hi,

You could use couple of counter and timer to define time since last push like:

Code:
local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
delta = timepush - timepushinit

if delta > 60 then
pushcount = 0
storage.set('lastpush', timepush)
end

if pushcount == 0 then
 -- do something
elseif pushcount == 1 and delta > 20 then
 --do something
elseif pushcount == 2 and delta > 30 then
 -- ...
else
 -- do something
end

pushcount = pushcount+1
storage.set('pushcount', pushcount)
Reply
#3
(08.06.2017, 10:28)mlaudren Wrote: Hi,

You could use couple of counter and timer to define time since last push like:

Code:
local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
delta = timepush - timepushinit

if delta > 60 then
pushcount = 0
storage.set('lastpush', timepush)
end

if pushcount == 0 then
 -- do something
elseif pushcount == 1 and delta > 20 then
 --do something
elseif pushcount == 2 and delta > 30 then
 -- ...
else
 -- do something
end

pushcount = pushcount+1
storage.set('pushcount', pushcount)

Hi mlaudren

thanks for your reply. I have written the code below but it is not working right. The code is working right at first time once, but when I change the temperature '5/3/0' manually, the Temp is not updated. Can you help?

local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
--Temp=grp.getvalue('5/3/0')
--storage.set('Temp',Temp)
local Temp = storage.get('Temp',0)
delta = timepush - timepushinit

grp.write('11/4/1',delta)
--grp.write('11/4/4',ActualTemp)

if delta > 15 then
pushcount = 0
storage.set('lastpush', timepush)
end

if pushcount == 0 then
ActualTemp=grp.getvalue('5/3/0')
storage.set('Temp', ActualTemp)
Temp=Temp+0.5
storage.set('Temp', Temp)
grp.write('11/4/3',Temp)
else
ActualTemp=grp.getvalue('5/3/0')
storage.set('Temp', ActualTemp)
Temp=Temp
storage.set('Temp', Temp)
grp.write('11/4/3',Temp)
end

pushcount = pushcount+1
storage.set('pushcount', pushcount)
--storage.set('Temp', Temp)



grp.write('11/4/2',pushcount)
--grp.write('11/4/3',Temp)
Reply
#4
(25.06.2017, 07:48)XSPA2474KW Wrote:
(08.06.2017, 10:28)mlaudren Wrote: Hi,

You could use couple of counter and timer to define time since last push like:

Code:
local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
delta = timepush - timepushinit

if delta > 60 then
pushcount = 0
storage.set('lastpush', timepush)
end

if pushcount == 0 then
 -- do something
elseif pushcount == 1 and delta > 20 then
 --do something
elseif pushcount == 2 and delta > 30 then
 -- ...
else
 -- do something
end

pushcount = pushcount+1
storage.set('pushcount', pushcount)

Hi mlaudren

thanks for your reply. I have written the code below but it is not working right. The code is working right at first time once, but when I change the temperature '5/3/0' manually, the Temp is not updated. Can you help?

local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
--Temp=grp.getvalue('5/3/0')
--storage.set('Temp',Temp)    
local Temp = storage.get('Temp',0)
delta = timepush - timepushinit

grp.write('11/4/1',delta)
--grp.write('11/4/4',ActualTemp)

if delta > 15 then
pushcount = 0
storage.set('lastpush', timepush)
end

if pushcount == 0 then
   ActualTemp=grp.getvalue('5/3/0')
   storage.set('Temp', ActualTemp)

   Temp=Temp+0.5
   storage.set('Temp', Temp)
grp.write('11/4/3',Temp)
else
   ActualTemp=grp.getvalue('5/3/0')
   storage.set('Temp', ActualTemp)
   Temp=Temp
   storage.set('Temp', Temp)
   grp.write('11/4/3',Temp)
end

pushcount = pushcount+1
storage.set('pushcount', pushcount)
--storage.set('Temp', Temp)



grp.write('11/4/2',pushcount)
--grp.write('11/4/3',Temp)

Hi,

I think you have a mistake in your code.
You read the address 5/3/0 and save the value in 'Temp'
but you never use this value after. so you only increase a value by 0.5 every time you press your button.

Look at the text I put in red.

What do you want to do?
if the user press 1 time, increase the setpoint to current+0.5?

Here is what the code do actually:


Code:
Get Temp, delta, pushcount;

if delta > 15 
 reset pushcount;
end

if pushcount == 0
  Get actualtemp from (5/...)
  Save actualtemp to 'Temp'
  Temp +0.5  <-- it's the variable temp not the same as 'Temp' first time is equal to 0
  Save Temp to 'Temp' <-- you override actualtemp you set just before
  Write Temp to Addr(11/...)
else
  Get actualtemp from (5/...)
  Save actualtemp to 'Temp'
  Temp=Temp <-- What the point to do this?
  Save Temp to 'Temp'  <-- same as above, you override actualtemp you set just before
  Write Temp to Addr(11/....)
end

increase pushcount
Save pushcount in 'pushcount'

Is it the same subject this question: https://forum.logicmachine.net/showthread.php?tid=866 ?
Reply
#5
Hi again

I want to increase the temperature by 0,5 every time i press the button but at the same time delta is > 60.

If I press the button and delta is < 60 do nothing.

Thanks in advance!
Reply
#6
Already answered in another topic of yours:
https://forum.logicmachine.net/showthread.php?tid=866
Reply
#7
Yes in fact is the same question!
Reply


Forum Jump: