Python utime.ticks_add() Examples

The following are 24 code examples of utime.ticks_add(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module utime , or try the search function .
Example #1
Source File: color15.py    From micropython-nano-gui with MIT License 6 votes vote down vote up
def multi_fields(t):
    print('Dynamic labels.')
    refresh(ssd, True)  # Clear any prior image
    nfields = []
    dy = wri.height + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)  # Use wri default colors
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Specify a border, color TBD
        y += dy

    end = utime.ticks_add(utime.ticks_ms(), t * 1000)
    while utime.ticks_diff(end, utime.ticks_ms()) > 0:
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            overrange =  None if value < 70 else YELLOW if value < 90 else RED
            field.value('{:5.2f}'.format(value), fgcolor = overrange, bdcolor = overrange)
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' OK ', True, fgcolor = RED)
    refresh(ssd)
    utime.sleep(1) 
Example #2
Source File: color96.py    From micropython-nano-gui with MIT License 6 votes vote down vote up
def multi_fields(t):
    print('multi_fields')
    refresh(ssd, True)  # Clear any prior image
    nfields = []
    dy = wri.height + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)  # Use wri default colors
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Specify a border, color TBD
        y += dy

    end = utime.ticks_add(utime.ticks_ms(), t * 1000)
    while utime.ticks_diff(end, utime.ticks_ms()) > 0:
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            overrange =  None if value < 70 else YELLOW if value < 90 else RED
            field.value('{:5.2f}'.format(value), fgcolor = overrange, bdcolor = overrange)
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' OK ', True, fgcolor = RED)
    refresh(ssd)
    utime.sleep(1) 
Example #3
Source File: core.py    From pysmartnode with MIT License 5 votes vote down vote up
def call_later(self, delay, callback, *args):
        self.call_at_(time.ticks_add(self.time(), int(delay * 1000)), callback, args) 
Example #4
Source File: core.py    From microhomie with MIT License 5 votes vote down vote up
def call_later_ms(self, delay, callback, *args):
        if not delay:
            return self.call_soon(callback, *args)
        self.call_at_(time.ticks_add(self.time(), delay), callback, args) 
Example #5
Source File: core.py    From microhomie with MIT License 5 votes vote down vote up
def call_later(self, delay, callback, *args):
        self.call_at_(time.ticks_add(self.time(), int(delay * 1000)), callback, args) 
Example #6
Source File: aswitch.py    From microhomie with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        if duration <= 0:
            duration = self.duration
        if self.can_alloc and self.tstop is None:  # No killer task is running
            self.tstop = time.ticks_add(time.ticks_ms(), duration)
            # Start a task which stops the delay after its period has elapsed
            self.loop.create_task(self.killer())
        self.tstop = time.ticks_add(time.ticks_ms(), duration) 
Example #7
Source File: ms_timer.py    From micropython-async with MIT License 5 votes vote down vote up
def __call__(self, ms):
        self.end = utime.ticks_add(utime.ticks_ms(), ms)
        return self 
Example #8
Source File: core.py    From micropython-async with MIT License 5 votes vote down vote up
def call_later_ms(self, delay, callback, *args):
        if not delay:
            return self.call_soon(callback, *args)
        self.call_at_(time.ticks_add(self.time(), delay), callback, args) 
Example #9
Source File: core.py    From micropython-async with MIT License 5 votes vote down vote up
def call_after(self, delay, callback, *args):
        self.call_at_lp_(time.ticks_add(self.time(), int(delay * 1000)), callback, *args) 
Example #10
Source File: core.py    From micropython-async with MIT License 5 votes vote down vote up
def call_after_ms(self, delay, callback, *args):
        self.call_at_lp_(time.ticks_add(self.time(), delay), callback, *args) 
Example #11
Source File: aswitch.py    From micropython-async with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        self._running = True
        if duration <= 0:
            duration = self.duration
        tn = time.ticks_add(time.ticks_ms(), duration)  # new end time
        self.verbose and self._tstop is not None and self._tstop > tn \
            and print("Warning: can't reduce Delay_ms time.")
        # Start killer if can allocate and killer is not running
        sk = self.can_alloc and self._tstop is None
        # The following indicates ._killer is running: it will be
        # started either here or in ._run
        self._tstop = tn
        if sk:  # ._killer stops the delay when its period has elapsed
            self.loop.create_task(self._killer()) 
Example #12
Source File: delay_ms.py    From micropython-async with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        now = ticks_ms()
        if duration <= 0:  # Use default set by constructor
            duration = self._duration
        self._retrn = None
        is_running = self()
        tstop = self._tstop  # Current stop time
        # Retriggering normally just updates ._tstop for ._timer
        self._tstop = ticks_add(now, duration)
        # Identify special case where we are bringing the end time forward
        can = is_running and duration < ticks_diff(tstop, now)
        if not is_running or can:
            schedule(self._do_trig, can) 
Example #13
Source File: rtc_time.py    From micropython-async with MIT License 5 votes vote down vote up
def ticks_add(a, b):
        return (a + b) % _PERIOD 
Example #14
Source File: core.py    From pysmartnode with MIT License 5 votes vote down vote up
def call_later_ms(self, delay, callback, *args):
        if not delay:
            return self.call_soon(callback, *args)
        self.call_at_(time.ticks_add(self.time(), delay), callback, args) 
Example #15
Source File: core.py    From uPyCam with Apache License 2.0 5 votes vote down vote up
def call_later(self, delay, callback, *args):
        self.call_at_(time.ticks_add(self.time(), int(delay * 1000)), callback, args) 
Example #16
Source File: delay_ms.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        now = ticks_ms()
        if duration <= 0:  # Use default set by constructor
            duration = self._duration
        self._retrn = None
        is_running = self()
        tstop = self._tstop  # Current stop time
        # Retriggering normally just updates ._tstop for ._timer
        self._tstop = ticks_add(now, duration)
        # Identify special case where we are bringing the end time forward
        can = is_running and duration < ticks_diff(tstop, now)
        if not is_running or can:
            schedule(self._do_trig, can) 
Example #17
Source File: core.py    From microdot with MIT License 5 votes vote down vote up
def call_later_ms(self, delay, callback, *args):
        if not delay:
            return self.call_soon(callback, *args)
        self.call_at_(time.ticks_add(self.time(), delay), callback, args) 
Example #18
Source File: core.py    From microdot with MIT License 5 votes vote down vote up
def call_later(self, delay, callback, *args):
        self.call_at_(time.ticks_add(self.time(), int(delay * 1000)), callback, args) 
Example #19
Source File: core.py    From micropython-samples with MIT License 5 votes vote down vote up
def call_later(self, delay, callback, *args):
        self.call_at_(time.ticks_add(self.time(), int(delay * 1000)), callback, args) 
Example #20
Source File: ms_timer.py    From micropython-samples with MIT License 5 votes vote down vote up
def __call__(self, ms):
        self.end = utime.ticks_add(utime.ticks_ms(), ms)
        return self 
Example #21
Source File: aswitch.py    From micropython-samples with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        if duration <= 0:
            duration = self.duration
        if self.can_alloc and self.tstop is None:  # No killer task is running
            self.tstop = time.ticks_add(time.ticks_ms(), duration)
            # Start a task which stops the delay after its period has elapsed
            self.loop.create_task(self.killer())
        self.tstop = time.ticks_add(time.ticks_ms(), duration) 
Example #22
Source File: ms_timer.py    From micropython-samples with MIT License 5 votes vote down vote up
def __call__(self, ms):
        self.end = utime.ticks_add(utime.ticks_ms(), ms)
        return self 
Example #23
Source File: delay_ms.py    From micropython-samples with MIT License 5 votes vote down vote up
def trigger(self, duration=0):  # Update end time
        self._running = True
        if duration <= 0:
            duration = self.duration
        tn = time.ticks_add(time.ticks_ms(), duration)  # new end time
        self.verbose and self._tstop is not None and self._tstop > tn \
            and print("Warning: can't reduce Delay_ms time.")
        # Start killer if can allocate and killer is not running
        sk = self.can_alloc and self._tstop is None
        # The following indicates ._killer is running: it will be
        # started either here or in ._run
        self._tstop = tn
        if sk:  # ._killer stops the delay when its period has elapsed
            asyncio.create_task(self._killer()) 
Example #24
Source File: core.py    From uPyCam with Apache License 2.0 5 votes vote down vote up
def call_later_ms(self, delay, callback, *args):
        if not delay:
            return self.call_soon(callback, *args)
        self.call_at_(time.ticks_add(self.time(), delay), callback, args)