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


Python pyb.delay方法代码示例

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


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

示例1: led_angle

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def led_angle():
    # make LED objects
    l1 = pyb.LED(1)
    l2 = pyb.LED(2)
    accel = STAccel()

    while True:
        # get x-axis
        x = accel.x() * 50

        # turn on LEDs depending on angle
        if x < -10:
            l2.on()
            l1.off()
        elif x > 10:
            l1.on()
            l2.off()
        else:
            l1.off()
            l2.off()

        # delay so that loop runs at at 1/50ms = 20Hz
        pyb.delay(50) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:25,代码来源:accelleds.py

示例2: timing

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def timing():                           # Check magnetometer call timings
    imu.mag_triggered = False           # May have been left True by above code
    start = pyb.micros()
    imu.get_mag_irq()
    t1 = pyb.elapsed_micros(start)
    start = pyb.micros()
    imu.get_mag_irq()
    t2 = pyb.elapsed_micros(start)
    pyb.delay(200)
    start = pyb.micros()
    imu.get_mag_irq()
    t3 = pyb.elapsed_micros(start)

    # 1st call initialises hardware
    # 2nd call tests it (not ready)
    # 3rd call tests ready (it will be after 200mS) and reads data
    print(t1, t2, t3) # 1st call takes 265uS second takes 175uS. 3rd takes 509uS 
开发者ID:micropython-IMU,项目名称:micropython-mpu9x50,代码行数:19,代码来源:irqtest.py

示例3: do_measurement

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def do_measurement():
    global nc
    global gnd
    global vcc
    global data
    global micros
    global timer
    global index
    # Send the START signal
    data.init(Pin.OUT_PP)
    data.low()
    micros.counter(0)
    while micros.counter() < 25000:
        pass
    data.high()
    micros.counter(0)
    while micros.counter() < 20:
        pass
    # Activate reading on the data pin
    index = 0
    data.init(Pin.IN, Pin.PULL_UP)
    # Till 5mS the measurement must be over
    pyb.delay(5)

# Parse the data read from the sensor 
开发者ID:kurik,项目名称:uPython-DHT22,代码行数:27,代码来源:DHT22.py

示例4: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def main():
    global var1, var2
    var1, var2 = 0, 0
    t2 = pyb.Timer(2, freq = 995, callback = update)
    t4 = pyb.Timer(4, freq = 1000, callback = update)
    for x in range(1000000):
        with mutex:             # critical section start
            a = var1
            pyb.udelay(200)
            b = var2
            result = a == b     # critical section end
        if not result:
            print('Fail after {} iterations'.format(x))
            break
        pyb.delay(1)
        if x % 1000 == 0:
            print(x)
    t2.deinit()
    t4.deinit()
    print(var1, var2) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:mutex_test.py

示例5: _power_off

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def _power_off(self):                       # turn of power and all signals
        self.Pin_RESET.low()
        self.Pin_PANEL_ON.low()
        self.Pin_BORDER.low()
        self.spi.deinit()
        self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
        self.Pin_SCK.low()
        self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
        self.Pin_MOSI.low()
        # ensure SPI MOSI and CLOCK are Low before CS Low
        self.Pin_EPD_CS.low()
        # pulse discharge pin
        self.Pin_DISCHARGE.high()
        pyb.delay(150)
        self.Pin_DISCHARGE.low()

# USER INTERFACE
# clear_screen() calls clear_data() and, if show, EPD_clear()
# showdata() called from show() 
开发者ID:peterhinch,项目名称:micropython-epaper,代码行数:21,代码来源:epdpart.py

示例6: _power_off

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def _power_off(self):                       # turn of power and all signals
        self.Pin_PANEL_ON.low()
#        self._SPI_send(b'\x00\x00')
        self.spi.deinit()
        self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
        self.Pin_SCK.low()
        self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
        self.Pin_MOSI.low()
        self.Pin_BORDER.low()
        # ensure SPI MOSI and CLOCK are Low before CS Low
        self.Pin_RESET.low()
        self.Pin_EPD_CS.low()
        # pulse discharge pin
        self.Pin_DISCHARGE.high()
        pyb.delay(150)
        self.Pin_DISCHARGE.low()

# One frame of data is the number of lines * rows. For example:
# The 2.7” frame of data is 176 lines * 264 dots. 
开发者ID:peterhinch,项目名称:micropython-epaper,代码行数:21,代码来源:epd.py

示例7: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def main():
    sw_state = False
    led = pyb.LED(1)
    switch = pyb.Switch()
    switch.callback(set_sw_state)
    accel = STAccel()
    hid = pyb.USB_HID()

    while True:
        if sw_state:
            x, y, z = accel.xyz()
            hid.send((0, int(x * MAG), int(-y * MAG), 0))

        pyb.delay(int(1000 / FREQ)) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:16,代码来源:accelmouse.py

示例8: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def main():
    serial = pyb.UART(2, BAUDRATE)
    lcd = STM_LCDShield()
    monitor = MidiMonitor(lcd)
    midiin = MidiIn(serial, monitor, debug=True)
    lcd.write("MIDI Mon ")
    pyb.delay(1000)
    lcd.write("ready")
    pyb.delay(1000)
    lcd.write("     ", col=9)

    while True:
        midiin.poll()
        pyb.delay(POLL_INTERVAL) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:16,代码来源:lcdmidimonitor.py

示例9: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def main():
    import pyb

    serial = pyb.USB_VCP()
    midi = MidiOut(serial, channel=1)
    switch = pyb.Switch()

    if hasattr(pyb, 'Accel'):
        accel = pyb.Accel()
        SCALE = 1.27
    else:
        from staccel import STAccel
        accel = STAccel()
        SCALE = 127

    while True:
        while not switch():
            pyb.delay(10)

        note = abs(int(accel.x() * SCALE))
        velocity = abs(int(accel.y() * SCALE))
        midi.note_on(note, velocity)

        while switch():
            pyb.delay(50)

        midi.note_off(note) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:29,代码来源:accelusbmidi.py

示例10: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def main():
    lcd = STM_LCDShield()

    lcd.write("ABCDEFGHIJKLMNOP")         # Send a string
    lcd.write("1234567890123456", row=1)  # Second line

    pyb.delay(3000) # 3 second delay
    lcd.clear()
    pyb.delay(500)

    # Send some more
    lcd.write("Hello, PyCologne")
    lcd.write("from MicroPython", row=1) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:15,代码来源:lcdshield.py

示例11: test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def test():
    mpu9150 = MPU9150('X')
    testfunc(mpu9150)
    print()
    pyb.delay(250)
    print("Repeating")
    testfunc(mpu9150) 
开发者ID:micropython-IMU,项目名称:micropython-mpu9x50,代码行数:9,代码来源:magtest.py

示例12: test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def test():
    led = pyb.LED(2)
    led1 = pyb.LED(3)
    dog = wdog()
    dog.start(1000)
    for x in range(10):
        led.toggle()
        pyb.delay(500)
        dog.feed()
    dog.start(4000)
    for x in range(20):
        led1.toggle()
        pyb.delay(500) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:15,代码来源:wdog.py

示例13: command

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def command(self, cmdstr, lines=1, waitfor=500, msgtext=None):
        #flush input
        #print(cmdstr)
        while self._uart.any():
            self._uart.readchar()
        self._uart.write(cmdstr)
        if msgtext:
            self._uart.write(msgtext)
        if waitfor>1000:
            pyb.delay(waitfor-1000)
        buf=self._uart.readline() #discard linefeed etc
        #print(buf)
        buf=self._uart.readline()
        #print(buf)
        if not buf:
            return None
        result = convert_to_string(buf)
        if lines>1:
            self.savbuf = ''
            for i in range(lines-1):
                buf=self._uart.readline()
                if not buf:
                    return result
                #print(buf)
                buf = convert_to_string(buf)
                if not buf == '' and not buf == 'OK':
                    self.savbuf += buf+'\n'
        return result 
开发者ID:jeffmer,项目名称:micropython-upyphone,代码行数:30,代码来源:sim800l.py

示例14: wakechars

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def wakechars(self):
        self._uart.write('AT\n')        # will be ignored
        pyb.delay(100) 
开发者ID:jeffmer,项目名称:micropython-upyphone,代码行数:5,代码来源:sim800l.py

示例15: sms_alert

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import delay [as 别名]
def sms_alert(self):
        self.command('AT+CALS=1,1\n')  # set ringtone
        pyb.delay(3000)
        self.command('AT+CALS=3,0\n')  # set ringtone 
开发者ID:jeffmer,项目名称:micropython-upyphone,代码行数:6,代码来源:sim800l.py


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