Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Arduino.h"
- #include <SPI.h>
- #include <SD.h>
- File myFile;
- int peakVal = 900;
- int timeCur = millis();
- void setup()
- {
- Serial.begin(9600);
- while (!Serial);
- Serial.print("Initializing SD card...");
- if (!SD.begin(10)) {
- Serial.println("initialization failed!");
- return;
- }
- Serial.println("initialization done.");
- }
- void loop()
- {
- int val = analogRead(A6);
- int c = millis();
- if (val > peakVal && c - timeCur > 500) {
- myFile = SD.open("hrv.txt", O_RDWR | O_APPEND);
- if (myFile) {
- int dif = c - timeCur;
- myFile.println(dif);
- myFile.close();
- Serial.println(dif);
- } else {
- if (!myFile) {
- myFile = SD.open("hrv.txt", O_RDWR | O_CREAT);
- if (!myFile) {
- Serial.println("Failed to open file");
- }
- }
- }
- timeCur = c;
- }
- delay(10);
- }
Add Comment
Please, Sign In to add comment