|
我用pulse sensor测量心率,并且用dht11测量温湿度。pulse sensor的用到端口A0和timer2定时器中断,dht11用端口7.现在的问题是,只要将这两个模块代码组合在一起,就只能读出心率,而温湿度都为0,只要分开测试都是好的,请问是什么原因?? - #include "dht11.h"
- #include "Wire.h"
- dht11 DHT11;
-
- #define DHT11PIN 8
- int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
- int blinkPin = 13; // pin to blink led at each beat
- int fadePin = 5; // pin to do fancy classy fading blink at each beat
- int fadeRate = 0; // used to fade LED on with PWM on fadePin
- // these variables are volatile because they are used during the interrupt service routine!
- volatile int BPM; // used to hold the pulse rate
- volatile int Signal; // holds the incoming raw data
- volatile int IBI = 600; // holds the time between beats, the Inter-Beat Interval
- volatile boolean Pulse = false; // true when pulse wave is high, false when it's low
- volatile boolean QS = false; // becomes true when Arduoino finds a beat.
- void setup()
- {
- Serial.begin(9600);
- pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
- pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
- interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
- Serial.println("DHT11 TEST PROGRAM ");
- }
- void loop()
- {
- Serial.println("\n");
-
- int chk = DHT11.read(DHT11PIN);
-
- Serial.print("Read sensor: ");
- switch (chk)
- {
- case DHTLIB_OK:
- Serial.println("OK");
- break;
- case DHTLIB_ERROR_CHECKSUM:
- Serial.println("Checksum error");
- break;
- case DHTLIB_ERROR_TIMEOUT:
- Serial.println("Time out error");
- break;
- default:
- Serial.println("Unknown error");
- break;
- }
- Serial.print("Humidity (%): ");
- Serial.println((float)DHT11.humidity, 2);
- Serial.print("Temperature (oC): ");
- Serial.println((float)DHT11.temperature, 2);
- delay(2000);
- // sendDataToProcessing('S', Signal); // send Processing the raw Pulse Sensor data
- if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
- fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse
- sendDataToProcessing('B',BPM); // send heart rate with a 'B' prefix
- sendDataToProcessing('Q',IBI); // send time between beats with a 'Q' prefix
- QS = false; // reset the Quantified Self flag for next time
- }
-
- ledFadeToBeat();
-
- delay(20); // take a break
- }
- void ledFadeToBeat(){
- fadeRate -= 15; // set LED fade value
- fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
- analogWrite(fadePin,fadeRate); // fade LED
- }
- void sendDataToProcessing(char symbol, int data ){
- Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
- Serial.println(data); // the data to send culminating in a carriage return
- }
复制代码 下面是定时器中断的代码 |
|