如果程序在使用后继续,所有类都会更改硬件状态,并且在不再需要它们时应取消初始化。为此,请调用deinit()或使用上下文管理器。有关更多信息,请参阅
Lifetime 和 ContextManagers。
例如:
import frequencyio
import time
from board import *
frequency = frequencyio.FrequencyIn(D13)
frequency.capture_period = 15
time.sleep(0.1)
此示例将初始化设备,设置
capture_period,然后休眠 0.1 秒。CircuitPython 会在程序完成后重置所有硬件时自动关闭 FrequencyIn 捕获。使用deinit() 或 with语句自行完成。
在这些板上可用
-  ATMegaZero ESP32-S2
-  Adafruit EdgeBadge
-  Adafruit Feather M4 CAN
-  Adafruit Feather M4 Express
-  Adafruit FunHouse
-  Adafruit Grand Central M4 Express
-  Adafruit Hallowing M4 Express
-  Adafruit ItsyBitsy M4 Express
-  Adafruit MagTag
-  Adafruit Matrix Portal M4
-  Adafruit Metro ESP32S2
-  Adafruit Metro M4 Airlift Lite
-  Adafruit Metro M4 Express
-  Adafruit Monster M4SK
-  Adafruit PyGamer
-  Adafruit PyPortal
-  Adafruit PyPortal Pynt
-  Adafruit PyPortal Titano
-  Adafruit Pybadge
-  Adafruit Trellis M4 Express
-  AloriumTech Evo M51
-  Artisense Reference Design RD00
-  BDMICRO VINA-D51
-  BastWiFi
-  CP32-M4
-  Capable Robot Programmable USB Hub
-  CircuitBrains Deluxe
-  CrumpS2
-  DynOSSAT-EDU-OBC
-  ESP 12k NodeMCU
-  Feather ESP32S2 without PSRAM
-  FeatherS2
-  FeatherS2 Neo
-  FeatherS2 PreRelease
-  Franzininho WIFI w/Wroom
-  Franzininho WIFI w/Wrover
-  Gravitech Cucumber M
-  Gravitech Cucumber MS
-  Gravitech Cucumber R
-  Gravitech Cucumber RS
-  HMI-DevKit-1.1
-  Kaluga 1
-  LILYGO TTGO T8 ESP32-S2 w/Display
-  MORPHEANS MorphESP-240
-  Mini SAM M4
-  Oak Dev Tech PixelWing ESP32S2
-  PyCubedv04
-  PyCubedv04-MRAM
-  PyCubedv05
-  PyCubedv05-MRAM
-  S2Mini
-  SAM E54 Xplained Pro
-  SAM32v26
-  Saola 1 w/Wroom
-  Saola 1 w/Wrover
-  Seeeduino Wio Terminal
-  Silicognition LLC M4-Shim
-  SparkFun MicroMod SAMD51 Processor
-  SparkFun Thing Plus - SAMD51
-  Sprite_v2b
-  TG-Boards' Datalore IP M4
-  Targett Module Clip w/Wroom
-  Targett Module Clip w/Wrover
-  The Open Book Feather
-  TinyS2
-  UARTLogger II
-  Winterbloom Sol
-  microS2
-  nanoESP32-S2  w/Wrover
-  nanoESP32-S2 w/Wroom
 
- 
class frequencyio.FrequencyIn(pin: microcontroller.Pin, capture_period: int = 10)
- 读取频率信号 - FrequencyIn 用于测量输入引脚上数字信号的频率(以赫兹为单位)。精度已经证明在 10% 以内,如果不是更好的话。建议使用多个样本的平均值来平滑读数。 - 目前无法检测到低于 1KHz 的频率。 - FrequencyIn 不会确定脉冲宽度(使用- PulseIn)。
 - 创建与给定引脚关联的 FrequencyIn 对象。 - 
- 参数
- 
 - 从引脚读取输入频率: - import frequencyio
import board
frequency = frequencyio.FrequencyIn(board.D11)
# Loop while printing the detected frequency
while True:
    print(frequency.value)
    # Optional clear() will reset the value
    # to zero. Without this, if the incoming
    # signal stops, the last reading will remain
    # as the value.
    frequency.clear()
- 
- 
capture_period:int
- 捕获测量周期。捕获周期越长,输入频率越低,测量得越准确。捕获周期越短,频率越高越准确。 - 
- 笔记 - 设置新的时- capture_period,所有以前的捕获信息都将通过调用- clear().
 
 
 - 
- 
deinit(self) → None
- 取消初始化 FrequencyIn 并释放任何硬件资源以供重用。 
 - 
- 
__enter__(self) → FrequencyIn
- 上下文管理器使用的无操作。 
 - 
- 
__exit__(self) → None
- 退出上下文时自动取消初始化硬件。有关更多信息,请参阅
Lifetime 和 ContextManagers 。 
 - 
- 
pause(self) → None
- 暂停频率捕获。 
 - 
- 
resume(self) → None
- 恢复频率捕获。 
 - 
- 
clear(self) → None
- 清除最后检测到的频率捕获值。 
 - 
- 
__get__(self, index: int) → int
- 返回最后捕获的频率值。