safwan092

404-Smart Watch Heart Project

Apr 11th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <DFPlayer_Mini_Mp3.h>
  3. #include <Wire.h>
  4. #include "SoftwareSerial.h"
  5. #include "RTClib.h"
  6. # define Start_Byte 0x7E
  7. # define Version_Byte 0xFF
  8. # define Command_Length 0x06
  9. # define End_Byte 0xEF
  10. # define Acknowledge 0x00
  11. # define ACTIVATED LOW
  12. SoftwareSerial serial(9, 8); // Tx = Pin 9
  13. SoftwareSerial mySerial(10, 11);
  14. RTC_DS3231 rtc;
  15. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  16. boolean isPlaying = false;
  17. int button1Pin = 7;
  18. int button1State = 0;
  19. int sensorValue;
  20.  
  21.  
  22. void setup () {
  23. pinMode(13, OUTPUT);
  24. pinMode(button1Pin, INPUT);
  25. Serial.begin(9600) ;
  26. mySerial.begin (9600);
  27. serial.begin(9600);
  28. delay(1);
  29. Serial.flush();
  30. serial.flush();
  31. delay(1000);
  32. isPlaying = false;
  33. mp3_set_serial (mySerial);
  34. mp3_set_volume (30);
  35. timeeSetup();
  36.  
  37. }//end of setup
  38.  
  39.  
  40.  
  41. void loop () {
  42. char serialData[30];
  43. int lf = 10;
  44. unsigned char read1, read2, read3;
  45. int temp_int;
  46. char temp_string[40];
  47. button1State = digitalRead(button1Pin);
  48. if (serial.available() >= 15) {
  49. temp_int = serial.readBytesUntil(lf, serialData, 15);
  50. read1 = ((serialData[1] - '0') * 100) + ((serialData[2] - '0') * 10) + (serialData[3] - '0');
  51. read2 = ((serialData[6] - '0') * 100) + ((serialData[7] - '0') * 10) + (serialData[8] - '0');
  52. read3 = ((serialData[11] - '0') * 100) + ((serialData[12] - '0') * 10) + (serialData[13] - '0');
  53. Serial.print("SYS: ");
  54. Serial.print(read1);
  55. Serial.print(" DIY: ");
  56. Serial.println(read2);
  57. Serial.print("Pulse/Min: ");
  58. Serial.println(read3);
  59. timee();
  60. if (read3 > 10) {
  61. mp3_play (1);
  62. delay (13000);
  63. mp3_stop ();
  64. for (int i = 0; i < 30; i++) {
  65. serialData[i] = 0;
  66. }
  67. read1 = 0;
  68. read2 = 0;
  69. read3 = 0;
  70. Serial.flush();
  71. serial.flush();
  72. }
  73. }
  74. else if (button1State == LOW) {
  75. mp3_play (1);
  76. delay (13000);
  77. mp3_stop ();
  78. }
  79. }//end of loop
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. void timeeSetup() {
  87.  
  88. if (! rtc.begin()) {
  89. Serial.println("Couldn't find RTC");
  90. while (1);
  91. }
  92.  
  93. if (rtc.lostPower()) {
  94. Serial.println("RTC lost power, lets set the time!");
  95. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  96. }
  97. }
  98.  
  99. void timee() {
  100. DateTime now = rtc.now();
  101. Serial.print(now.year(), DEC);
  102. Serial.print('/');
  103. Serial.print(now.month(), DEC);
  104. Serial.print('/');
  105. Serial.println(now.day(), DEC);
  106. Serial.print(" (");
  107. Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  108. Serial.println(") ");
  109. Serial.print(now.hour(), DEC);
  110. Serial.print(':');
  111. Serial.print(now.minute(), DEC);
  112. Serial.print(':');
  113. Serial.print(now.second(), DEC);
  114. Serial.println();
  115. }
  116.  
  117. // name audio files to play [ mp3_play (3); ] == [ ./mp3/0003.mp3 ]
Add Comment
Please, Sign In to add comment