当前位置: 首页>>代码示例>>Python>>正文


Python pyb.millis函数代码示例

本文整理汇总了Python中pyb.millis函数的典型用法代码示例。如果您正苦于以下问题:Python millis函数的具体用法?Python millis怎么用?Python millis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了millis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: interpolateStep

 def interpolateStep(self):
     if not self.interpolating:
         return
     complete = self.servoCount
     while (pyb.millis() - self.lastFrame < BIOLOID_FRAME_LENGTH):
         pass
     self.lastFrame = pyb.millis()
     for i in range(self.servoCount):
         diff = self.nextPose[i] - self.pose[i]
         if diff == 0:
             complete -= 1
         else:
             if diff > 0:
                 if diff < self.speed[i]:
                     self.pose[i] = self.nextPose[i]
                     complete -= 1
                 else:
                     self.pose[i] += self.speed[i]
             else:
                 if (-diff) < self.speed[i]:
                     self.pose[i] = self.nextPose[i]
                     complete -= 1
                 else:
                     self.pose[i] -= self.speed[i]
     if complete <= 0:
         self.interpolating = False
     self.writePose()
开发者ID:JonHylands,项目名称:roz,代码行数:27,代码来源:BioloidController.py

示例2: makegauge

    def makegauge(self):
        '''
        Generator refreshing the raw measurments.
        '''
        delays = (5, 8, 14, 25)
        while True:
            self._bmp_i2c.mem_write(0x2E, self._bmp_addr, 0xF4)
            t_start = pyb.millis()
            while pyb.elapsed_millis(t_start) <= 5: # 5mS delay
                yield None
            try:
                self.UT_raw = self._bmp_i2c.mem_read(2, self._bmp_addr, 0xF6)
            except:
                yield None

            self._bmp_i2c.mem_write((0x34+(self.oversample_setting << 6)),
                                    self._bmp_addr,
                                    0xF4)

            t_pressure_ready = delays[self.oversample_setting]
            t_start = pyb.millis()
            while pyb.elapsed_millis(t_start) <= t_pressure_ready:
                yield None
            try:
                self.MSB_raw = self._bmp_i2c.mem_read(1, self._bmp_addr, 0xF6)
                self.LSB_raw = self._bmp_i2c.mem_read(1, self._bmp_addr, 0xF7)
                self.XLSB_raw = self._bmp_i2c.mem_read(1, self._bmp_addr, 0xF8)
            except:
                yield None
            yield True
开发者ID:janpagon,项目名称:micropython-bmp180,代码行数:30,代码来源:bmp180.py

示例3: pb

    def pb(self,who,unused=None,unusedA=None):
        if ((pyb.millis()  - self.pbTime) < State.pbBounceDelay):
            self.pbTime = pyb.millis()
            State.printT('PB BOUNCE!! delta millis:\t' +  str(pyb.millis()  - self.pbTime))
            return False
        State.printT('PB delta millis:\t' +  str(pyb.millis()  - self.pbTime))
        self.pbTime = pyb.millis()
        whoFuncs = (
            # this either steps the seq or toggles splitpot tracking if not sequencing
            (self.pb0Func,),  # pb 0 # either step sequence or toggle tracking if not sequencing
            # this is the one saves the preset,      
            (self.turnOnYellowLed, self.saveCurrentConfAsPreset),          # pb 1
            # Tremolo
            (self.toggleTrem,),                       # pb 2
            # Vibrato
            (self.toggleVib,),                        # pb 3
            (self.lcdMgr.onLeftButton,),              # pb 4
            (self.lcdMgr.onRightButton,))             # pb 5

        State.printT('PB:\t' + str(who))  
        res = False         
        for f in whoFuncs[who]:
            res = f() or res
        State.printT('pb returning: ' +str(res))
        return res # True if who in [2,3] else False
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:25,代码来源:app.py

示例4: send

    def send(self, buf, timeout=500):
        # power up
        self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
        pyb.udelay(150)

        # send the data
        self.cs.low()
        self.spi.send(W_TX_PAYLOAD)
        self.spi.send(buf)
        if len(buf) < self.payload_size:
            self.spi.send(b'\x00' * (self.payload_size - len(buf))) # pad out data
        self.cs.high()

        # enable the chip so it can send the data
        self.ce.high()
        pyb.udelay(15) # needs to be >10us
        self.ce.low()

        # blocking wait for tx complete
        start = pyb.millis()
        while pyb.millis() - start < timeout:
            status = self.reg_read_ret_status(OBSERVE_TX)
            if status & (TX_DS | MAX_RT):
                break

        # get and clear all status flags
        status = self.reg_write(STATUS, RX_DR | TX_DS | MAX_RT)
        if not (status & TX_DS):
            raise OSError("send failed")

        # power down
        self.reg_write(CONFIG, self.reg_read(CONFIG) & ~PWR_UP)
开发者ID:A-L-E-X,项目名称:micropython,代码行数:32,代码来源:nrf24l01.py

示例5: enterObstacleAvoidanceScanState

 def enterObstacleAvoidanceScanState(self):
     # this function shuts down the FSM for a second or two
     self.log('Entering ObstacleAvoidanceScanState')
     self.ikEngine.travelX = 0
     self.ikEngine.travelRotZ = 0
     self.ikEngine.setupForWalk()
     self.ikEngine.bodyPosX = -50  # move the body forwards so the head clears the legs
     self.ikEngine.setupForWalk()
     self.ikEngine.bodyPosX = 0  # it will move back the next time the IK engine runs
     blue = pyb.LED(BLUE_LED)
     blue.on()
     openAngle = self.mapObstacleSpace()
     blue.off()
     if openAngle is None:
         # we didn't find any open areas, so switch to walking mode which will re-trigger obstacle mode again
         self.log("No openings found from scan")
         self.obstacleScanTurnTime = pyb.millis()
     else:
         # The IK Engine uses radians/s for rotation rate, so figure out the delta in radians and thus given a fixed
         # rotation rate figure out how long we need to turn in order to end up pointing in that direction
         openAngleRadians = math.radians(openAngle)
         self.obstacleScanTurnTime = pyb.millis() + int((abs(openAngleRadians) / FRONT_OBSTACLE_TURN_SPEED) * 1000)
         if openAngle > 0:
             self.log("Found opening at angle %d - turning left" % openAngle)
             self.ikEngine.travelRotZ = FRONT_OBSTACLE_TURN_SPEED
         else:
             self.log("Found opening at angle %d - turning right" % openAngle)
             self.ikEngine.travelRotZ = -FRONT_OBSTACLE_TURN_SPEED
开发者ID:raymondcheng008,项目名称:roz,代码行数:28,代码来源:roz.py

示例6: master

        def master():
            fut = Future()
            self.assertEqual((yield from x(10, 'happy')), 'happy')
            self.assertEqual((yield from w(x(10, 'pleased'), fut)), 'pleased')
            self.assertEqual(fut.result(), 'pleased')
            #logging.basicConfig(level=logging.DEBUG)
            #log.debug("Now %f", self.loop.time())

            # One that completes before the timeout
            t0 = pyb.millis()
            fut = Future()
            self.loop.call_soon(w(x(20, 'good'), fut))
            v = yield from wait_for(fut, 50)
            self.assertEqual(v, 'good')
            et = pyb.elapsed_millis(t0)
            self.assertTrue(20 <= et < 25,
                            'et was %rms (expected 20-25ms)' % et)

            # One that hits the timeout
            t0 = pyb.millis()
            fut = Future()
            self.loop.call_soon(w(x(20, 'fine'), fut))
            with self.assertRaises(TimeoutError):
                v = yield from wait_for(fut, 10)
            et = pyb.elapsed_millis(t0)
            self.assertTrue(10 <= et < 15,
                            'et was %rms (expected 10-15ms)' % et)
开发者ID:pramasoul,项目名称:micropython-coro,代码行数:27,代码来源:test_apyb.py

示例7: update

 def update(self):
     if pyb.millis() - self.lastDebounceTime > self.debounceDelay:
         reading = self.pin.value()
         if reading != self.lastReading:
             # we got a new value
             self.lastDebounceTime = pyb.millis()
             self.lastReading = reading
             if reading == self.onState and self.doOn:
                 self.doOn()
开发者ID:P3PO,项目名称:ArduGuitar,代码行数:9,代码来源:debouncePushbutton.py

示例8: tone

def tone(f,t,b=0):
    global bz
    p = int(1000000/f)
    t1 = pyb.millis()+t
    while pyb.millis() < t1:
        bz.high()
        pyb.udelay(p)
        bz.low()
        pyb.udelay(p)
    if b!=0: pyb.delay(b)
开发者ID:liedra,项目名称:adventure-emf,代码行数:10,代码来源:main.py

示例9: stableValue

def stableValue(pin,stabilityPeriod=20):
    res = pin.value()
    if res:
        return res
    readTime = millis()
    while(millis()-readTime < stabilityPeriod):
        if res != pin.value():
            res = pin.value()
            readTime = millis()
        delay(1)
    return res
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:11,代码来源:hardware.py

示例10: update

 def update(self):
     ok,v = self.readA()
     if ok:  # read went ok
         curZone = self.detectionZone(v - self.baseVal)
         if (curZone): # we have passed a threshold,
             if curZone != self.prevZone: # changed zones!
                 self.tf() #tfunc must be not None
                 self.lastActionTime = millis()
                 self.prevZone = curZone
         if millis() - self.lastActionTime > self.timeOut:
             self.of() # oFunc must be not None
             self.lastActionTime = millis()
开发者ID:P3PO,项目名称:ArduGuitar,代码行数:12,代码来源:hardware.py

示例11: _get_B5

    def _get_B5(self):
        '''
        Calculates and sets compensation value B5.
        '''
        if (self._B5 is None) or ((pyb.millis()-self._t_B5) > self._dt_B5):
            self.get_temperature()
            X1 = (self._UT-self._AC6)*self._AC5/2**15
            X2 = self._MC*2**11/(X1+self._MD)
            self._B5 = X1+X2
            self._t_B5 = pyb.millis()

        return
开发者ID:CRImier,项目名称:micropython-bmp180,代码行数:12,代码来源:bmp180.py

示例12: FLASH_WaitForLastOperation

def FLASH_WaitForLastOperation(timeout):
    tickstart = pyb.millis()
    while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET):
        if (timeout != HAL_MAX_DELAY):
            if (timeout == 0 or (pyb.millis() - tickstart) > timeout):
                return False
    if __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
                            FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR |
                            FLASH_FLAG_PGSERR | FLASH_FLAG_RDERR) != RESET:
        # FLASH_SetErrorCode()
        return False
    return True
开发者ID:xyb,项目名称:upy-stm-flash,代码行数:12,代码来源:rdp.py

示例13: run

  def run( self ) :
    self._display.fill(0)
    sw = pyb.Switch()
    lasttime = pyb.millis()
    while sw() == False :
      pyb.delay(DISPLAY_DELAY)
      distance = self._getdistance()

      thistime = pyb.millis()
      t = thistime - lasttime
      self.printdistance(distance)
      self._rangepoint.update(self._display, distance, t / 1000.0)
      lasttime = thistime
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:13,代码来源:DistanceDisplay.py

示例14: master

def master():
    nrf = NRF24L01(SPI(2), Pin('Y5'), Pin('Y4'), payload_size=8)

    nrf.open_tx_pipe(pipes[0])
    nrf.open_rx_pipe(1, pipes[1])
    nrf.start_listening()

    num_needed = 16
    num_successes = 0
    num_failures = 0
    led_state = 0

    print('NRF24L01 master mode, sending %d packets...' % num_needed)

    while num_successes < num_needed and num_failures < num_needed:
        # stop listening and send packet
        nrf.stop_listening()
        millis = pyb.millis()
        led_state = max(1, (led_state << 1) & 0x0f)
        print('sending:', millis, led_state)
        try:
            nrf.send(struct.pack('ii', millis, led_state))
        except OSError:
            pass

        # start listening again
        nrf.start_listening()

        # wait for response, with 250ms timeout
        start_time = pyb.millis()
        timeout = False
        while not nrf.any() and not timeout:
            if pyb.elapsed_millis(start_time) > 250:
                timeout = True

        if timeout:
            print('failed, respones timed out')
            num_failures += 1

        else:
            # recv packet
            got_millis, = struct.unpack('i', nrf.recv())

            # print response and round-trip delay
            print('got response:', got_millis, '(delay', pyb.millis() - got_millis, 'ms)')
            num_successes += 1

        # delay then loop
        pyb.delay(250)

    print('master finished sending; succeses=%d, failures=%d' % (num_successes, num_failures))
开发者ID:19emtuck,项目名称:micropython,代码行数:51,代码来源:nrf24l01test.py

示例15: update

 def update(self):
     if self.autoOff:  # we look for timeout, otherwise keep going
         if millis() - self.lastActionTime > self.timeOut:
             self.of() # oFunc must be not None
             self.lastActionTime = millis()
             return  # we're done!
     ok,v = self.readA()
     if ok:  # read went ok
         curZone = self.detectionZone(v - self.baseVal)
         if (curZone): # we have passed a threshold,
             if curZone != self.prevZone: # changed zones!
                 self.tf() #tfunc must be not None
                 self.lastActionTime = millis()
                 self.prevZone = curZone
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:14,代码来源:hardware.py


注:本文中的pyb.millis函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。