12345678910111213141516171819202122232425262728293031323334 |
- class Lapse:
- def __init__(self,intv=1.0,oneshot=None):
- self.cunit = intv
- self.intv = int( intv * 1000000 )
- self.next = self.intv
- self.last = Time.ticks_us()
- self.count = 1.0
- if oneshot:
- self.shot = False
- return
- self.shot = None
- #FIXME: pause / resume(reset)
- def __bool__(self):
- if self.shot is True:
- return False
- t = Time.ticks_us()
- self.next -= ( t - self.last )
- self.last = t
- if self.next <= 0:
- if self.shot is False:
- self.shot = True
- self.count+= self.cunit
- self.next = self.intv
- return True
- return False
- export('Lapse')
|