使用.NET MF 实现数字反射传感器?
我使用带有微控制器和数字反射传感器的.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论