Guest User

Untitled

a guest
Mar 11th, 2015
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. //PWM on pins 3 and 11 will not work when using this code, because we are using Timer 2!
  2. //The following variables are automatically updated:
  3. //Signal : int that holds the analog signal data straight from the sensor. updated every 2mS.
  4. //IBI : int that holds the time interval between beats. 2mS resolution.
  5. //BPM : int that holds the heart rate value, derived every beat, from averaging previous 10 IBI values.
  6. //QS : boolean that is made true whenever Pulse is found and BPM is updated. User must reset.
  7. //Pulse : boolean that is true when a heartbeat is sensed then false in time with pin13 LED going out.
  8.  
  9. int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
  10. int blinkPin = 13; // pin to blink led at each beat
  11. int fadePin = 5; // pin to do fancy classy fading blink at each beat
  12. int fadeRate = 0; // used to fade LED on with PWM on fadePin
  13.  
  14.  
  15. // these variables are volatile because they are used during the interrupt service routine!
  16. volatile int BPM; // used to hold the pulse rate
  17. volatile int Signal; // holds the incoming raw data
  18. volatile int IBI = 600; // holds the time between beats, must be seeded!
  19. volatile boolean Pulse = false; // true when pulse wave is high, false when it's low
  20. volatile boolean QS = false; // becomes true when Arduoino finds a beat.
  21.  
  22.  
  23. void setup(){
  24. pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
  25. //pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
  26. Serial.begin(4800); // we agree to talk fast!
  27. interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
  28. analogReference(EXTERNAL); // powering by 3.3V
  29. }
  30.  
  31.  
  32.  
  33. void loop(){
  34. //sendDataToProcessing('S', Signal); // send Processing the raw Pulse Sensor data
  35. if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
  36. //fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse
  37. //sendDataToProcessing('B',BPM); // send heart rate with a 'B' prefix
  38. //sendDataToProcessing('Q',IBI); // send time between beats with a 'Q' prefix
  39. sendBPM(BPM);
  40. QS = false; // reset the Quantified Self flag for next time
  41. }
  42.  
  43. //ledFadeToBeat();
  44.  
  45. delay(20); // take a break
  46. }
  47.  
  48. void sendBPM(int BPM){
  49. Serial.println(BPM);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment