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


Python time.ticks_ms函数代码示例

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


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


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