Netduino Plus 2的脉冲传感器编码出错了

时间:2016-12-02 21:59:03

标签: visual-studio-2010 microcontroller electronics .net-micro-framework netduino

我目前正在使用.net微框架在Netduino Plus 2上做一个项目,这需要我为脉冲传感器编码。我试过找到脉冲传感器的代码,但无济于事。我尝试将AnalogInput代码用于脉冲传感器,但输出值似乎不对(尽管传感器附近没有心跳,但仍有一个恒定的高值)。请指教!

以下是我目前的心跳传感器代码:

  using System;
  using System.Net;
  using System.Net.Sockets;
  using System.Threading;
  using Microsoft.SPOT;
  using Microsoft.SPOT.Hardware;
  using SecretLabs.NETMF.Hardware;
  using SecretLabs.NETMF.Hardware.Netduino;

  namespace heartrate
   {
   public class Program
  {
  public static void Main()
   {


    SecretLabs.NETMF.Hardware.AnalogInput rate =
    new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);
    int sensorvalue = 0;
    while (true)
    {
        sensorvalue = rate.Read();
        Debug.Print("" + sensorvalue);
        Thread.Sleep(1000);
    }
   }
 }
 }

以下是传感器的规格,传感器的外观以及连接方式。 http://www.elecrow.com/wiki/index.php?title=Pulse_Sensor (本教程适用于arduino,但我认为接线类似于Netduino)

1 个答案:

答案 0 :(得分:0)

很难说没有关于脉冲设备及其连接方式的规格。对于模拟输入和在我的最新项目(https://github.com/osstekz/cncBuddy)中的输出我使用类InputPort& OutputPort(Microsoft.SPOT.Hardware) 例如:

public NESControllerAdapter(Cpu.Pin pinClk, Cpu.Pin pinLatch, Cpu.Pin pinData1/*, Cpu.Pin pinData2 = Cpu.Pin.GPIO_NONE*/) {
        // Binds to all pins
        this._outpClk = new OutputPort(pinClk, false);
        this._outpLatch = new OutputPort(pinLatch, false);
        this._inpData1 = new InputPort(pinData1, false, Port.ResistorMode.Disabled);
        //if (pinData2 != Cpu.Pin.GPIO_NONE) this._inpData2 = new InputPort(pinData2, false, Port.ResistorMode.Disabled);
        }

...然后就像你的rate.Read();环

public int ButtonPressed() {
    // Locks all parms
    this._PinTick(this._outpLatch);

    // Reads plug state value
    for (int i = 0; i < CncBuddyShared.iTOTALNESCONTROLLERBUTTONS; ++i) {
        // Read the value, if true return this index as the first pressed button
        if (this._inpData1.Read() == false) return i;

        // Selects the next value
        this._PinTick(this._outpClk);
        }
    return NESCONTROLLER_PRESSEDBUTTOM_NONE;
    }