乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      學(xué)習(xí)micropython定時(shí)器

       新用戶5228KeDY 2023-02-02 發(fā)布于北京

      使用計(jì)時(shí)器的好處,是實(shí)現(xiàn)類似并行處理的功能,也就是一個(gè)應(yīng)用里只能有一個(gè)while True,兩個(gè)以上都是不可以的;但是如果使用計(jì)時(shí)器,就可以同時(shí)運(yùn)行多個(gè)while True,這和Arduinovoid loop()是類似的,實(shí)際Arduino也有timer庫和timer1庫。Micropython下的machine庫的Timer是一個(gè)類,在文檔(Jan 28,2023)的位置:

      MicroPython libraries/

      MicroPython-specific libraries/

      machine - functions related to the hardware/

      class Timer - control hardware timers

      只有兩個(gè)函數(shù),一個(gè)初始化,一個(gè)取消初始化。

      1、初始化Timer.init(*, mode=Timer.PERIODIC, freq=- 1, period=- 1, callback=None)

      參數(shù):Timer.ONE_SHOT,運(yùn)行一次拉倒,Timer.PERIODIC周期性運(yùn)行。freq單位Hz, period單位milliseconds。當(dāng)頻率和周期同時(shí)被設(shè)置時(shí),周期被忽略,以頻率為準(zhǔn)。callback回調(diào)函數(shù)。

      2、銷毀Timer.deinit()。

      測(cè)試:

      代碼:

      #---------------------------------------------------------#參考https://www./blogs/tutorials/tutorials-for-rpi-pi-pico-with-micropython-code#----------------------------------------------------------from machine import Pin, Timerimport time
      #PICO的LED在GPIO25上;PICOW,GPIO0LED = Pin(25, Pin.OUT)n=0#while,一旦有亮的LED,確保關(guān)掉while LED.value()==1: LED.value(0) #回調(diào)函數(shù)至少有一個(gè)參數(shù)def Flash_LED(t1): LED.value(not LED.value()) print('LED')
      def INC(t2): global n n=n+1 if n<10 else 0 print(n)
      #樸素的用法,tim1運(yùn)行一次就失效Timer.ONE_SHOTtim1 = Timer()tim1.init(period=5000, mode = Timer.ONE_SHOT, callback = Flash_LED)
      #tim2開啟之后一直嗷嗷跑,直到被關(guān)掉Timer.PERIODICtim2 = Timer() tim2.init(freq = 2, mode = Timer.PERIODIC, callback = INC)
      #True循環(huán)和Timer不打架while True: if LED.value()==1: time.sleep(3) #殺死tim2 tim2.deinit() #關(guān)燈 LED.off()
      '''#若只用一個(gè)計(jì)時(shí)器,或者不期望以后再關(guān)掉,對(duì)象也不用聲明,直接初始化Timer(period=5000, mode = Timer.ONE_SHOT, callback = Flash_LED)Timer(freq = 2, mode = Timer.PERIODIC, callback = INC)'''

        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多