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.

Short - Long press
#1
Here's a simple script that calculate the time difference between 1 (true) and 0 (false) of a 1 bit object.
I have extended it with some examples on how to use it to calculate the ON time of an object and as a working hour timer.
 
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041
long = 10 --set long press in seconds value = event.getvalue() object = grp.find(event.dst) if value then   if not storage.get('start') then     storage.set('start', object.updatetime)   end else   start = storage.get('start')   if start then       diff = os.difftime(object.updatetime, start)   end   storage.delete('start') end if diff then   if diff >= long then     --long press time in seconds       log('long press: '..diff..' seconds')      else     --short press time in seconds       log('short press: '..diff..' seconds')   end   --time the object was ON in seconds   log('object was ON for: '..diff..' seconds')       hour = math.floor((diff / 3600)+ 0.5)     if not storage.get('counter') then     counter = hour       storage.set('counter', counter)     else       counter = storage.get('counter')       counter = counter + hour       storage.set('counter', counter)     end       --total time the object was ON in hours       log('hour counter: '..counter..' hours') end
Reply


Forum Jump: