Hi,
I need your help.
I want to write a program for my Arduino but I am facing a situation.
I bought a SD shield which is working with my SD card using programs in the Arduino software.
I have 2 signals, a source signal and a received signal. I am doing a comparaison of the first signal with a value I fixed, then I save the time at which this event approximately occured, Then if my received signal respect a second condition, I take the difference between the two moments those events happened and I want to save that difference in a txt document on a SD card, the fact.
I've seen on Google that saving a file took time so I created a condition on the total saving of the file but with or without it my program does'not work meaning that my SD has not data on it when I connect it to my computer.
Thank you for your help.
I hope to have been the most understandable.
This is my code :
#include <SPI.h>
#include <SD.h>int sonarPin = A3;
int sourcePin = A1;
unsigned long time;int valSource = 0;
int valSonar = 0;
float valDepassementSonar = 1.2;
float valDepassementSource = 3.6;
float timeSource = 0;
float timeSonar = 0;
float timetot = 0;
int i = 0;File myFile;
void setup() {
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}void loop() {
if (10000000>=itimeSource){
myFile.close();
myFile = SD.open("sonardate.txt", FILE_WRITE);
i = i+1;
}
valSource = analogRead(sourcePin);
valSonar = analogRead(sonarPin);
if (valSource>=valDepassementSource204.6) {
timeSource = micros();
if (valSonar>=valDepassementSonar*204.6) {
timeSonar = micros();
timetot = timeSonar - timeSource;
myFile.println(timetot);
}
}
Serial.println(timeSonar-timeSource);
}
Programme_Arduino.ino (1.13 KB)