Adafruit Adafruit植物区系/脉冲传感器/ Neopixel不变色

时间:2018-12-09 20:21:15

标签: arduino adafruit neopixel

我们的代码无法识别我们的心跳阈值。我们有一个心率传感器,一个adafruit植物区系,4个LED和一个neopixel。我们正在尝试使新像素和LED根据某人的脉动闪烁。而且,我们正在尝试获取它,以便当某人的心率较高(变为粉红色)而较低(变为蓝色)时,neopixel的颜色从正常(白色)改变。

/*  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.

0 个答案:

没有答案