• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python time.ticks_ms函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

def main():
    # Executed on boot
    global switchPin
    global switchstate
    global lightstate
    switchPin = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
    cm.setAP(False)   # We don't want AP in work mode by default
    savedData = boot.readSession()
    lightstate = int(savedData[1])
    switchstate = int(savedData[2])
    triac.activate(lightstate)
    print("Bulb reinitialised")
    attemptConnect()

    # Main program
    while(MainLoop):
        global compareTime
        time.sleep_ms(checkFrequency)
        if time.ticks_diff(time.ticks_ms(), compareTime) > reconnAttemptInterval:
            attemptConnect()
            print("Done MQTT connect")
            compareTime = time.ticks_ms()
        if not emergencyMode:
            checkInputChange(0)
            if cm.mqttActive:
                mqtt.check_msg()
        else:
            checkInputChange(1)
开发者ID:DanijelMi,项目名称:Micropython_MQTT_8266bulb,代码行数:28,代码来源:workMode.py


示例2: makegauge

 def makegauge(self):
     '''
     Generator refreshing the raw measurments.
     '''
     delays = (5, 8, 14, 25)
     while True:
         self._bmp_i2c.writeto_mem(self._bmp_addr, 0xF4, bytearray([0x2E]))
         t_start = time.ticks_ms()
         while (time.ticks_ms() - t_start) <= 5: # 5mS delay
             yield None
         try:
             self.UT_raw = self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xF6, 2)
         except:
             yield None
         self._bmp_i2c.writeto_mem(self._bmp_addr, 0xF4, bytearray([0x34+(self.oversample_setting << 6)]))
         t_pressure_ready = delays[self.oversample_setting]
         t_start = time.ticks_ms()
         while (time.ticks_ms() - t_start) <= t_pressure_ready:
             yield None
         try:
             self.MSB_raw = self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xF6, 1)
             self.LSB_raw = self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xF7, 1)
             self.XLSB_raw = self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xF8, 1)
         except:
             yield None
         yield True
开发者ID:micropython-IMU,项目名称:micropython-bmp180,代码行数:26,代码来源:bmp180.py


示例3: blink_all_timed

    def blink_all_timed(self, color, blink_duration, brightness=1):
        """ Blink the entire stand at 2Hz for blink_duration, turns off afterwards
        
        Arguments:
            color : can be 'red', 'green', 'blue', 
                    or a tuple of (r,g,b) where r, g, and b are between 0 and 255
            blink_duration : duration to blink for in seconds
            brightness : between 0 and 1, 0 is off, 1 is full brightness
        """
        start_time = time.ticks_ms()
        
        run_time = time.ticks_diff(time.ticks_ms(), start_time) 
        
        while run_time/1000 < blink_duration:
            if run_time % 500 < 250: 
                self.turn_all_to_color(color, brightness)
            else:
                self.turn_all_off()
            
            time.sleep_ms(1)
            run_time = time.ticks_diff(time.ticks_ms(), start_time) 

        # Ensure that all are off 
        self.turn_all_off()
        
开发者ID:DocVaughan,项目名称:CRAWLAB-Code-Snippets,代码行数:24,代码来源:main.py


示例4: ride

    def ride(self, crank):
        global DISTANCE_TARGET
        if self.distance_travelled <= DISTANCE_TARGET:
            # Pull the crank values and calculate the wheel rotations 
            crank_counter_local = str(crank.counter // 2)
            wheel_counter_local_calc = (crank.counter // 2) * 2.8 
            wheel_counter_local = str(wheel_counter_local_calc)
                
            # Workout distance travelled from previous loop
            last_distance_travelled = self.distance_travelled
            calc_current_timestamp = time.ticks_ms() / 1000
            current_timestamp = str(time.ticks_ms() / 1000)

            # Workout the Distance Travelled and covert from meters per second to miles per hour
            self.distance_travelled = (wheel_counter_local_calc * DISTANCE_PER_REVOLUTION) * 2.2237
            distance_loop = self.distance_travelled - last_distance_travelled
            self.speed = (self.distance_travelled / (calc_current_timestamp - self.starttime)) 
            self.distance_remaining = DISTANCE_TARGET - self.distance_travelled
            print("Wheel Counter: " + str(wheel_counter_local_calc) + " | Average Speed (miles per hour): " + str(self.speed) + " | Distance Remaining (meters): " + str(self.distance_remaining)) 

            # Write out speed and distance left to LCD display 
            self.lcd.clear()
            self.lcd.message("AMPH:" + str(int(self.speed)) + "\nMtrs:" + str(int(self.distance_remaining)))

            # this is sent by the gateway
            #json_str = '{"RiderName":"'+rider_name+'","Company":"'+company+'","BadgeNumber":'+badge_number+',"EventID":"'+event_id+'","RideTimestamp":'+start_timestamp+',"BikeID":'+bike_id+',"RideStatus":"'
            #+rider_status+'","RideInfo":[{"CounterTimestamp":'+current_timestamp+',"CrankCounter":'+crank_counter_local+',"WheelCounter":'+wheel_counter_local+'}]}'
            #json_reading = json.loads(json_str)     
            # print(json_reading)
            # TODO: Publish json_reading to TOPIC, QOS
            
            return False
        else:
            return True
开发者ID:danicampora,项目名称:lopy_ews,代码行数:34,代码来源:rider.py


示例5: testProto16

def testProto16():
	start = time.ticks_ms()
	print("Bounce LED on PROTO16-I2C card")

	# Set all of the pins to outputs
	for bit in range(0,16):
		mcp23017.digitalWrite(bit,0)	# preset to zero so LED doesn't blink
		mcp23017.pinMode(bit,mcp23017.OUTPUT)
		if mcp23017.digitalRead(bit)!=0:
			print("testProto16 (1): readback failed - expected 0, got 1")
			sys.exit(1)
		if mcp23017.digitalRead(bit)!=0:
			print("testProto16 (2): readback failed - expected 0, got 1")
			sys.exit(1)
		
	# Blink all LEDs
	for loopCount in range(0,10):
		for bit in range(0,32):
			mcp23017.digitalWrite(bit,1)
			time.sleep(0.5)
			if mcp23017.digitalRead(bit)!=1:
				print("testProto16 (3): readback failed - expected 1, got 0")
				sys.exit(1)
			mcp23017.digitalWrite(bit,0)
	deltaTime = time.ticks_diff(start, time.ticks_ms())/1000
	print("Test completed, time =",abs(deltaTime))
开发者ID:douggilliland,项目名称:lb-Python-Code,代码行数:26,代码来源:testProto16.py


示例6: _read_timeout

def _read_timeout(cnt, timeout_ms=2000):
    time_support = "ticks_ms" in dir(time)
    s_time = time.ticks_ms() if time_support else 0
    data = sys.stdin.read(cnt)
    if len(data) != cnt or (time_support and time.ticks_diff(time.ticks_ms(), s_time) > timeout_ms):
        return None
    return data
开发者ID:BetaRavener,项目名称:uPyLoader,代码行数:7,代码来源:download.py


示例7: do_connect

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    
    start = time.ticks_ms() # get millisecond counter
    
    
    if not sta_if.isconnected():
        print('Connecting to network...')
        sta_if.active(True)
        sta_if.connect(WIFI_SSID, WIFI_PASSWORD)
        while not sta_if.isconnected():
            print('Waiting for connection...')
            time.sleep_ms(500)
            pin.value(not pin.value()) # Toggle the LED while trying to connect
            
            # compute time difference since we started looking for the network
            # If it's greater than 10s, we'll time out and just start up as 
            # an access point.
            delta = time.ticks_diff(time.ticks_ms(), start) 
            if delta > 10000:
                print('\r\nTimeout on network connection. Please:')
                print(' * check the SSID and password \r\n * connect to the esp8266 Access Point\r\n')
                break
            
    print('Network Configuration:', sta_if.ifconfig())
    pin.high() # Turn off the LED connected
开发者ID:DocVaughan,项目名称:CRAWLAB-Code-Snippets,代码行数:27,代码来源:esp8266_MicroPy_boot_Estop.py


示例8: step

 def step(self, num_steps):
     if time.ticks_diff(self.time0, time.ticks_ms()) > self.delay:
         steps_left = abs(num_steps)
         
         if num_steps > 0: self.direction = True
         if num_steps < 0: self.direction = False
         
         # decrement the number of steps, moving one step each time:
         while steps_left > 0:
             now = time.ticks_us()
             
             # move only if the appropriate delay has passed:
             if time.ticks_diff(self.last_step_time, now) >= self.step_delay:
                 self.last_step_time = now
                 
                 if self.direction:
                     self.step_number += 1
                     if self.step_number == self.step_num:
                         self.step_number = 0
                 else:
                     if self.step_number == 0:
                        self.step_number = self.step_num
                     self.step_number -= 1
                 steps_left -= 1
                 
                 self.step_motor(self.step_number % 4)
         self.time0 = time.ticks_ms()
开发者ID:Woz4tetra,项目名称:Atlas,代码行数:27,代码来源:stepper.py


示例9: deployfile

    def deployfile(self, filename, addr):
        pages = self.getlayout()
        page_erased = [False] * len(pages)
        buf = bytearray(128) # maximum payload supported by I2C protocol
        start_addr = addr
        self.setwraddr(addr)
        fsize = os.stat(filename)[6]
        local_sha = hashlib.sha256()
        print('Deploying %s to location 0x%08x' % (filename, addr))
        with open(filename, 'rb') as f:
            t0 = time.ticks_ms()
            while True:
                n = f.readinto(buf)
                if n == 0:
                    break

                # check if we need to erase the page
                for i, p in enumerate(pages):
                    if p[0] <= addr < p[0] + p[1]:
                        # found page
                        if not page_erased[i]:
                            print('\r% 3u%% erase 0x%08x' % (100 * (addr - start_addr) // fsize, addr), end='')
                            self.pageerase(addr)
                            page_erased[i] = True
                        break
                else:
                    raise Exception('address 0x%08x not valid' % addr)

                # write the data
                self.write(buf)

                # update local SHA256, with validity bits set
                if addr == start_addr:
                    buf[0] |= 3
                if n == len(buf):
                    local_sha.update(buf)
                else:
                    local_sha.update(buf[:n])

                addr += n
                ntotal = addr - start_addr
                if ntotal % 2048 == 0 or ntotal == fsize:
                    print('\r% 3u%% % 7u bytes   ' % (100 * ntotal // fsize, ntotal), end='')
            t1 = time.ticks_ms()
        print()
        print('rate: %.2f KiB/sec' % (1024 * ntotal / (t1 - t0) / 1000))

        local_sha = local_sha.digest()
        print('Local SHA256: ', ''.join('%02x' % x for x in local_sha))

        self.setrdaddr(start_addr)
        remote_sha = self.calchash(ntotal)
        print('Remote SHA256:', ''.join('%02x' % x for x in remote_sha))

        if local_sha == remote_sha:
            print('Marking app firmware as valid')
            self.markvalid()

        self.reset()
开发者ID:DanielO,项目名称:micropython,代码行数:59,代码来源:mboot.py


示例10: loop

 def loop(self):
     lastDisplayTime = time.ticks_ms()
     while True:
         now = time.ticks_ms()
         if now - lastDisplayTime > self.displayDelta:
             lastDisplayTime = now
             line = 'X: ' + str(round(self.js.readX())) + '  Y: ' + str(round(self.js.readY()))
             print(line)
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:8,代码来源:app.py


示例11: timeit

    def timeit():
        spi = SpiMaster(1, baudrate=int(pyb.freq()[3] / 16))
        start = ticks_ms()

        for i in range(2 ** 10):
            spi.write_data(b'abcdefgh' * 4)
            spi.read_data()

        print("Millisecond ticks elapsed: %i" % ticks_diff(ticks_ms(), start))
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:9,代码来源:spimaster.py


示例12: testDigio128

def testDigio128():
	start = time.ticks_ms()
	print("Testing DIGIO-128 card")
	# Set all of the pins to pulled up inputs
	for bit in range(0,128):
		digio128.pinMode(bit,digio128.INPUT_PULLUP)
	# verify all pins were set to pulled up inputs
	for bit in range(0,128):
		if digio128.digitalRead(bit) != 1:
			print("testDigio128(1): Expected pullup on input pin")
			sys.exit(1)
	# Write bits one at a time to 0
	for writtenBit in range(0,128):
		digio128.pinMode(writtenBit,digio128.OUTPUT)
		digio128.digitalWrite(writtenBit,0)
		loopBackBit=writtenBit^0x1f
		# Check all of the pins to be sure only one pin was set to 0
		for checkingBit in range(0,128):
			readValue = digio128.digitalRead(checkingBit)
			# The bit being tested should be 0
			if writtenBit == checkingBit:	# The bit being tested
				if readValue != 0:
					print("testDigio128(2): Expected a 0, got a 1")
					print("testDigio128(2): writtenBit =",writtenBit)
					print("testDigio128(2): checkingBit =",checkingBit)				
					print("testDigio128(2): readValue =",readValue)				
					print("testDigio128(2): loopBackBit =",loopBackBit)
					sys.exit(1)
			# The looped back bit should be 0
			elif checkingBit==loopBackBit:	# The loopback cable here
				if readValue!=0:
					print("testDigio128(3): Expected a 0, got a 1")
					print("testDigio128(3): writtenBit",writtenBit)
					print("testDigio128(3): checkingBit =",checkingBit)				
					print("testDigio128(3): readValue =",readValue)				
					print("testDigio128(3): Expected a 1, got a 0")
					print("testDigio128(3): loopBackBit =",loopBackBit)
					sys.exit(1)
				digio128.digitalWrite(writtenBit,1)
				if digio128.digitalRead(loopBackBit)!= 1:
					print("testDigio128(4): Expected a 1, got a 0")					
				digio128.digitalWrite(writtenBit,0)
			# All the other pins should be 1
			elif readValue!=1:
				print("testDigio128(5): writtenBit =",writtenBit)				
				print("testDigio128(5): checkingBit =",checkingBit)				
				print("testDigio128(5): readValue =",readValue)				
				print("testDigio128(5): Expected a 1, got a 0")
				print("testDigio128(5): loopBackBit =",loopBackBit)
				sys.exit(1)
		digio128.pinMode(writtenBit,digio128.INPUT_PULLUP)
	deltaTime = time.ticks_diff(start, time.ticks_ms())/1000
	print("Test passed, time =",abs(deltaTime))
开发者ID:douggilliland,项目名称:lb-Python-Code,代码行数:53,代码来源:testDigio128.py


示例13: tst

def tst():
    dat = machine.Pin("GP30")
    ow = OneWire(dat)
    ds = FDS1820(ow)
    print("devices:", ds.roms)
    start = time.ticks_ms()
    for x in range(0, 3):
        print("temperatures:", ds.slow_read_temps())
    print(time.ticks_diff(start, time.ticks_ms()))
    start = time.ticks_ms()
    for x in range(0, 3):
        print("temperatures:", ds.read_temps())
    print(time.ticks_diff(start, time.ticks_ms()))
开发者ID:scudderfish,项目名称:FDS18X20,代码行数:13,代码来源:__init__.py


示例14: poll_beam

 def poll_beam(self):
     if self.beam.interrupted():
         self.beam_interrupted_t = ticks_ms()
         self.beam_ever_interrupted = True
         return True
     else:
         return False
开发者ID:pramasoul,项目名称:pyboard-music-detector,代码行数:7,代码来源:bug.py


示例15: poll_mic

 def poll_mic(self):
     if self.mic.excited():
         self.mic_excited_t = ticks_ms()
         self.mic_ever_excited = True
         return True
     else:
         return False
开发者ID:pramasoul,项目名称:pyboard-music-detector,代码行数:7,代码来源:bug.py


示例16: test_main

def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
    lcd.putstr("It Works!\nSecond Line")
    sleep_ms(3000)
    lcd.clear()
    count = 0
    while True:
        lcd.move_to(0, 0)
        lcd.putstr("%7d" % (ticks_ms() // 1000))
        sleep_ms(1000)
        count += 1
        if count % 10 == 3:
            print("Turning backlight off")
            lcd.backlight_off()
        if count % 10 == 4:
            print("Turning backlight on")
            lcd.backlight_on()
        if count % 10 == 5:
            print("Turning display off")
            lcd.display_off()
        if count % 10 == 6:
            print("Turning display on")
            lcd.display_on()
        if count % 10 == 7:
            print("Turning display & backlight off")
            lcd.backlight_off()
            lcd.display_off()
        if count % 10 == 8:
            print("Turning display & backlight on")
            lcd.backlight_on()
            lcd.display_on()
开发者ID:dhylands,项目名称:python_lcd,代码行数:34,代码来源:esp8266_i2c_lcd_test.py


示例17: wait_response

 def wait_response(self):
     start = time.ticks_ms()
     while 1:
         try:
             self.i2c.readfrom_into(self.addr, self.buf1)
             n = self.buf1[0]
             break
         except OSError as er:
             time.sleep_us(500)
         if time.ticks_diff(time.ticks_ms(), start) > 5000:
             raise Exception('timeout')
     if n >= 129:
         raise Exception(n)
     if n == 0:
         return b''
     else:
         return self.i2c.readfrom(self.addr, n)
开发者ID:DanielO,项目名称:micropython,代码行数:17,代码来源:mboot.py


示例18: refresh

 def refresh(self):
     """
     Start a new measurement.
     """
     self._cs.off()
     time.sleep_us(10)
     self._cs.on()
     self._last_measurement_start = time.ticks_ms()
开发者ID:psy0rz,项目名称:stuff,代码行数:8,代码来源:max6675.py


示例19: show

 def show():
     lights.update()
     if not verbose:
         return
     print('{}: laser {}'.format(ticks_ms(), beam.interrupted()), end=' ')
     sleep(0.1)
     print('deck %s' % deck.status(), end=' ')
     if piano.playing():
         print('Piano being played', end='')
     print()
开发者ID:pramasoul,项目名称:pyboard-music-detector,代码行数:10,代码来源:simp.py


示例20: dl

def dl(url, debug=False):
    import uhashlib
    import ubinascii

    proto, dummy, host, path = url.split("/", 3)
    ai = socket.getaddrinfo(host, 80)
    addr = ai[0][4]
    s = socket.socket()
    s.settimeout(10)
    try:
        s.connect(addr)
        s.write(b"GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (path, host))
        size = 0
        hash = uhashlib.sha1()
        t = time.ticks_ms()
        buf = s.read(2000)
        assert buf, buf
        if debug:
            print("initial response:", buf)
        header, buf = buf.split(b"\r\n\r\n", 1)
        #print(header)
        #print(buf)
        hash.update(buf)
        size += len(buf)
        while 1:
            buf = s.read(1024)
            if buf == b"": break
            hash.update(buf)
            size += len(buf)
            sys.stdout.write("%dK\r" % (size >> 10))
#            sta.active(False)
        delta = time.ticks_diff(time.ticks_ms(), t)
        #print()
        print("Size :", size)
        print("Speed: %s bytes/s" % (size / delta * 1000))
        print("Elapsed: %s" % (delta / 1000))
        sha = str(ubinascii.hexlify(hash.digest()), "ascii")
        print("SHA1 :", sha)
        return size, sha
    finally:
        s.close()
开发者ID:pfalcon,项目名称:micropython-projs,代码行数:41,代码来源:test_dl.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.time函数代码示例发布时间:2022-05-27
下一篇:
Python time.struct_time函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap