使用.NET MF 实现数字反射传感器?

发布于 2024-12-13 04:06:10 字数 1138 浏览 0 评论 0原文

我使用带有微控制器和数字反射传感器的.NET MF。我需要在 C# 中实现以下伪代码以从传感器读取数据。我使用 GHIElectronics.NETMF.FEZ 作为输入/输出端口。这是我正在使用的产品 http://www.sparkfun.com/products/9454

int QRE1113_Pin = 2; //connected to digital 2

void setup(){
Serial.begin(9600);
}

void loop(){

int QRE_Value = readQD();
Serial.println(QRE_Value); 

}

int readQD(){
//Returns value from the QRE1113 
//Lower numbers mean more refleacive
//More than 3000 means nothing was reflected.
pinMode( QRE1113_Pin, OUTPUT );
digitalWrite( QRE1113_Pin, HIGH );
delayMicroseconds(10);
pinMode( QRE1113_Pin, INPUT );

long time = micros();

//time how long the input is HIGH, but quit after 3ms as nothing happens after that
while (digitalRead(QRE1113_Pin) == HIGH && micros() - time < 3000);
int diff = micros() - time;

return diff;

编辑:我用来

new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO44, false, Port.ResistorMode.Disabled)

创建输入端口和

new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO44, false)

创建输出端口,但我不知道如何将引脚模式从输出更改为输入或将引脚设置为高电平

I'm using .NET MF with a microcontroller and a digital reflectance sensor. I need to implement the following pseudocode in C# to read from the sensor. I am using GHIElectronics.NETMF.FEZ for input/output ports. This is the product I'm using http://www.sparkfun.com/products/9454

int QRE1113_Pin = 2; //connected to digital 2

void setup(){
Serial.begin(9600);
}

void loop(){

int QRE_Value = readQD();
Serial.println(QRE_Value); 

}

int readQD(){
//Returns value from the QRE1113 
//Lower numbers mean more refleacive
//More than 3000 means nothing was reflected.
pinMode( QRE1113_Pin, OUTPUT );
digitalWrite( QRE1113_Pin, HIGH );
delayMicroseconds(10);
pinMode( QRE1113_Pin, INPUT );

long time = micros();

//time how long the input is HIGH, but quit after 3ms as nothing happens after that
while (digitalRead(QRE1113_Pin) == HIGH && micros() - time < 3000);
int diff = micros() - time;

return diff;

EDIT: I'm using

new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO44, false, Port.ResistorMode.Disabled)

to create inputports and

new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO44, false)

to create outputports, but I don't know how to change pin mode from Out to In or set a pin as HIGH

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文