我们的代码没有认识到我们的心率阈值 . 我们有心率传感器,adafruit植物,4个LED和一个neopixel . 我们正试图让neopixel和LED根据某人的脉搏闪烁 . 而且我们试图让它能够在某人的心率更高(变成粉红色)和更低(变成蓝色)时,新像素从正常(白色)改变颜色 .

/*  PulseSensor™ Starter Project and Signal Tester
 *  The Best Way to Get Started  With, or See the Raw Signal of, your PulseSensor™ & Arduino.
 *
 *  Here is a link to the tutorial
 *  https://pulsesensor.com/pages/code-and-guide
 *
 *  WATCH ME (Tutorial Video):
 *  https://www.youtube.com/watch?v=82T_zBZQkOE
 *
 *
-------------------------------------------------------------
1) This shows a live human Heartbeat Pulse.
2) Live visualization in Arduino's Cool "Serial Plotter".
3) Blink an LED on each Heartbeat.
4) This is the direct Pulse Sensor's Signal.
5) A great first-step in troubleshooting your circuit and connections.
6) "Human-readable" code that is newbie friendly."

*/
   #include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, 10, NEO_GRB + NEO_KHZ800);
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN              10
#define NUMPIXELS        1
//  Variables
int PulseSensorPurplePin = 6;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED9 = 9;   //  The on-board Arduion LED

int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 16;            // Determine which Signal to "count as a beat", and which to ingore.


// The SetUp Function:
void setup() {
  pinMode(9,OUTPUT);         // pin that will blink to your heartbeat!
     Serial.begin(9600);         // Set's up Serial Communication at certain speed.
  pinMode(10,OUTPUT);
   Serial.begin(9600);         // Set's up Serial Communication at certain speed.
  pixels.begin(); 
}
// The Main Loop Function
void loop() {

  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value.
                                              // Assign this value to the "Signal" variable.

   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.

if(Signal > Threshold)
{ 
  Serial.print(Signal); Serial.println(" lux"); 
  pixels.setPixelColor(0, pixels.Color(216,191,216));
  pixels.show();
   digitalWrite(LED9,HIGH);}
else if (12 > Signal > 16){
  pixels.setPixelColor(0,pixels.Color(0,0,255));
  pixels.show(); 
  delay (10);
  digitalWrite(LED9,LOW);                //  Else, the sigal must be below "550", so "turn-off" this LED.

   }
   else (18 > Signal > 20); {
   pixels.setPixelColor(0,pixels.Color(255,0,0));
   pixels.show();
   delay (10); 
   }
}
                         // If the signal is above "550", then "turn-on" Arduino's on-Board LED.