我正在使用带有微控制器和数字反射传感器的.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)
创建输出端口,但我不知道如何将引脚模式从Out更改为In或将引脚设置为HIGH