执行演示代码

执行以下操作,以在昉·星光 2的Debian系统上运行演示代码:

  1. 找到测试代码edge_detection_with_waiting_time.py所在的目录:
    1. 执行以下命令以获取VisionFive.gpio所在的目录:
      pip show VisionFive.gpio
      示例结果:
      Location: /usr/local/lib64/python3.9/site-packages
      注:

      实际输出取决于应用的安装方式。

    2. 如前一步输出中所示,执行以下操作进入目录/usr/local/lib64/python3.9/site-packages
      cd /usr/local/lib64/python3.9/site-packages
    3. 执行以下命令进入sample-code目录:
      cd ./VisionFive/sample-code/
  2. sample-code目录下,执行以下命令以运行演示代码:
    sudo python edge_detection_with_waiting_time.py

    或者,您也可以执行以下命令:

    sudo python3 edge_detection_with_waiting_time.py
    结果:
    • 终端显示如下:
      # python3 edge_detection_with_waiting_time.py 
      *-----------------------Case 1-----------------------------------------------------*
      Note: don't press the key on pin 37 once within 5 seconds !!!
    • 等待5秒后,终端显示如下:
      Edge hasn't been detected within 5 seconds  while setting 5 seconds to timeout.
      The return value of GPIO.event_detected(37) within 5 seconds: False
      
      *-----------------------Case 2-----------------------------------------------------------------------*
      Please press the key on pin 37 once at any time !!!
    • 最后根据提示按下按键,终端显示如下:
      Edge has detected while setting -1 to timeout,
      timeout -1 means waiting until edge is detected.
      
      The return value (True) of GPIO.event_detected(37) should be True.
      The return value (False) of GPIO.event_detected(37) should be False, because of the secondly reading.