Guest User

Untitled

a guest
Jul 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <SPI.h>
  3. #include <SD.h>
  4.  
  5. File myFile;
  6.  
  7. int peakVal = 900;
  8. int timeCur = millis();
  9.  
  10. void setup()
  11. {
  12. Serial.begin(9600);
  13.  
  14. while (!Serial);
  15. Serial.print("Initializing SD card...");
  16. if (!SD.begin(10)) {
  17. Serial.println("initialization failed!");
  18. return;
  19. }
  20. Serial.println("initialization done.");
  21. }
  22.  
  23. void loop()
  24. {
  25. int val = analogRead(A6);
  26. int c = millis();
  27.  
  28. if (val > peakVal && c - timeCur > 500) {
  29. myFile = SD.open("hrv.txt", O_RDWR | O_APPEND);
  30. if (myFile) {
  31. int dif = c - timeCur;
  32. myFile.println(dif);
  33. myFile.close();
  34. Serial.println(dif);
  35. } else {
  36. if (!myFile) {
  37. myFile = SD.open("hrv.txt", O_RDWR | O_CREAT);
  38. if (!myFile) {
  39. Serial.println("Failed to open file");
  40. }
  41. }
  42. }
  43. timeCur = c;
  44. }
  45. delay(10);
  46. }
Add Comment
Please, Sign In to add comment