Logic Machine Forum
1 bit counter - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: 1 bit counter (/showthread.php?tid=5758)



1 bit counter - Haug1 - 22.11.2024

Hi,
I want to create a script where, upon receiving a 1-bit input, it triggers another G/A to increment a counter by 1.
Each time a 1 is received, the counter should increase by +1.

And other question will this counter have a memenry. So after a power loss will this counter still beĀ "alive"?


RE: 1 bit counter - JRP - 25.11.2024

Hello

You can use the graphical logical function editor (FB editor) for this case.
There is already a counter available.

Regards.


RE: 1 bit counter - Daniel - 25.11.2024

Create event script on your object which is triggering counter and change group address in this script to your counter object
Code:
counterObject = '1/1/1'
value = event.getvalue()

if value then
    value = grp.getvalue(counterObject)
    grp.write(counterObject, value +1)
end



RE: 1 bit counter - Haug1 - 25.11.2024

(25.11.2024, 11:58)Daniel Wrote: Create event script on your object which is triggering counter and change group address in this script to your counter object
Code:
counterObject = '1/1/1'
value = event.getvalue()

if value then
    value = grp.getvalue(counterObject)
    grp.write(counterObject, value +1)
end

Perfect. Thanks.
Does it have memory on this in case of a reboot? Or will it then start at 0 again?


RE: 1 bit counter - Daniel - 25.11.2024

The scripts checks current value of counter object and adds 1 to it. Objects are synced every 30 min so if power down will happen you may loos last 30min of counting and after power up it will keep counting where the last value was saved.