-1

我目前正在使用 .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)

4

1 回答 1

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;
    }
于 2016-12-03T04:51:57.017 回答