首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microbit上Micropython命令time_pulse_us的问题

Microbit上Micropython命令time_pulse_us的问题
EN

Stack Overflow用户
提问于 2021-01-12 11:52:18
回答 1查看 148关注 0票数 1

我想请你帮个忙。我试图将距离传感器连接到我的微型钻头上,但当我使用"time_pulse_us“命令时,它总是给出-2或-1。我阅读了文档,我理解这些数字的含义,但我认为命令有问题,或者我可能用错了方法。

在这方面,我编写了一个简单的代码片段来测试该命令。你能告诉我它出了什么问题吗?

代码语言:javascript
复制
from microbit import * //to import microbit modules
from machine import *  //to import the time_pulse_us command


while True:
    pin1.write_digital(0)
    time = time_pulse_us(pin2, 1) //to begin the timing
    pin1.write_digital(1)         //this pin is connected to an LED    
    sleep(1000)
    value = pin2.read_digital()  //gives 1, as this pin is reading the voltage from the led
    pin1.write_digital(0)        //this will make the time_pulse command to end timing
    display.scroll(time)         //it should display the duration of the pulse. 
                                 //Displays -2 instead.
    display.scroll(value)        //gives 1, as expected

为什么这不起作用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-12 21:00:34

time_pulse_us()按顺序运行,而不是在后台运行,因此在调用时,它将等待1秒,直到引脚达到1,但它不会这样做,因此在程序进入下一个命令write_digital(1)之前,time将被设置为-2。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65677802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档