Ciao,
avrei bisogno di scrivere in un file txt un timestamp (e anche altri valori ricavati da altri sensori).
Ho ricavato il timestamp con un metodo ma non riesco a passare il risultato a File.printl() per inserirlo nel file.
Allego il codice
#include <DS3231.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
File myFile;
DS3231 Clock;
bool Century = false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}
void timestamp(String) {
int second = Clock.getSecond();
int minute = Clock.getMinute();
int hour = Clock.getHour(h12, PM);
int date = Clock.getDate();
int month = Clock.getMonth(Century);
int year = Clock.getYear();
Serial.print("20");
Serial.print(year, DEC);
Serial.print('-');
Serial.print(month, DEC);
Serial.print('-');
Serial.print(date, DEC);
Serial.print(' ');
Serial.print(hour, DEC);
Serial.print(':');
Serial.print(minute, DEC);
Serial.print(':');
Serial.print(second, DEC);
Serial.print('\n');
}
void loop() {
String time;
timestamp(time);
// put your main code here, to run repeatedly:
//opening file
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println(timestamp(time));
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay(5000);
}
L'errore:
Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P"
C:\Users\pgraziano84\Documents\Arduino\esempi\SD_Card\sd_example\write_timestamp\write_timestamp.ino: In function 'void loop()':
write_timestamp:58: error: invalid use of void expression
myFile.println(timestamp(time));
^
exit status 1
invalid use of void expressionThis report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.