Advertisement
WongWC1998

Untitled

Apr 22nd, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "MAX30105.h"
  3.  
  4. MAX30105 particleSensor;
  5. const int MPU = 0x68;
  6. float Accel_X, Accel_Y, Accel_Z;
  7.  
  8. class FilterBuBp2
  9. {
  10. public:
  11. FilterBuBp2()
  12. {
  13. for(int i=0; i <= 4; i++)
  14. v[i]=0.0;
  15. }
  16. private:
  17. float v[5];
  18. public:
  19. float step(float x) //class II
  20. {
  21. v[0] = v[1];
  22. v[1] = v[2];
  23. v[2] = v[3];
  24. v[3] = v[4];
  25. v[4] = (5.586996620231363987e-3 * x)
  26. + (-0.80080264666570755150 * v[0])
  27. + (3.37021291056280425380 * v[1])
  28. + (-5.33686791231501622690 * v[2])
  29. + (3.76742616976629829395 * v[3]);
  30. return
  31. (v[0] + v[4])
  32. - 2 * v[2];
  33. }
  34. };
  35.  
  36. FilterBuBp2 c_filter;
  37. long present, seconds, past, green, past2, present2;
  38. long past_gValue[8]={9999,9999,9999,9999,9999,9999,9999,9999};
  39. int arr_size=7;
  40. bool beatG;
  41. int flag;
  42. float voltage;
  43.  
  44. void setup()
  45. {
  46. Serial.begin(9600);
  47.  
  48. // Initialize sensor
  49. if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
  50. {
  51. Serial.println("MAX30105 was not found.");
  52. while (1);
  53. }
  54.  
  55. //Setup to sense a nice looking saw tooth on the plotter
  56. byte ledBrightness = 0x3F; //Options: 0=Off to 255=50mA
  57. byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
  58. byte ledMode = 3; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  59. int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  60. int pulseWidth = 411; //Options: 69, 118, 215, 411
  61. int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
  62.  
  63. particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
  64.  
  65. particleSensor.setPulseAmplitudeRed(0x00);
  66. particleSensor.setPulseAmplitudeIR(0x00);
  67. particleSensor.setPulseAmplitudeGreen(0xFF);
  68.  
  69. past = millis();
  70. past2 = millis();//send data every 0.5s
  71.  
  72. Wire.endTransmission(true); //end the transmission
  73.  
  74. Wire.beginTransmission(MPU); // Start communication with MPU6050 // MPU=0x68
  75. Wire.write(0x6B); // Talk to the register 6B
  76. Wire.write(0x00); // Make reset - place a 0 into the 6B register
  77. Wire.endTransmission(true); //end the transmission
  78. Serial.println("MAX30105 was not found.");
  79. Serial.println("MAX30105 was not found.");
  80.  
  81. }
  82.  
  83. void loop()
  84. {
  85. green=c_filter.step(particleSensor.getGreen());
  86.  
  87.  
  88. past_gValue[0]=green;
  89.  
  90. for(int i = 0; i<arr_size; i++){
  91. past_gValue[arr_size-i]=past_gValue[arr_size-1-i];
  92. }
  93.  
  94.  
  95. for(int i = 0; i<arr_size; i++){
  96. if (past_gValue[arr_size-i]>past_gValue[arr_size-1-i]){
  97. flag++;
  98. }
  99. }
  100.  
  101. if (flag==arr_size-1) {
  102. present=millis();
  103. if ((present-past) > 300) {
  104. seconds=60000/(present-past);
  105. }
  106. past=millis();
  107. /*Serial.print(200);
  108. }
  109. else {
  110. Serial.print(0);*/
  111. }
  112.  
  113. Wire.endTransmission();
  114. present2=millis();
  115.  
  116. if (present2-past2 > 500) {
  117. Serial.print("hr=");
  118. Serial.print(seconds);
  119. Serial.print(",sv=");
  120. past2=millis();
  121.  
  122. voltage = analogRead(PA3);
  123. voltage = voltage * 3.3 / 4096;
  124. Serial.print(voltage);
  125.  
  126. // default dry skin is around 0.5-0.6, wet skin around 0.9-1.1, threshold should be 0.7-0.8
  127.  
  128. Serial.print(",mm=");
  129.  
  130. Wire.beginTransmission(MPU);
  131. Wire.write(0x43); // Accel data first register address 0x43
  132. Wire.endTransmission();
  133. Wire.requestFrom(MPU, 6); // Read 4 registers total, each axis value is stored in 2 registers
  134. Accel_X = (Wire.read() << 8 | Wire.read()) / 131.0;
  135. Accel_Y = (Wire.read() << 8 | Wire.read()) / 131.0;
  136. Accel_Z = (Wire.read() << 8 | Wire.read()) / 131.0;
  137. Serial.print(Accel_Z);
  138. Serial.println(",");
  139. }
  140.  
  141.  
  142. flag=0;
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement