Dunque ho effettuato le modifiche che mi hai detto,ma mi da un errore su
accelerometer.getAcceleration(&ax,&ay,&az);
dice
sketch_apr11a:23: error: expected constructor, destructor, or type conversion before '.' token
sketch_apr11a:24: error: expected constructor, destructor, or type conversion before '(' token
sketch_apr11a.ino: In function 'void loop()':
sketch_apr11a:66: error: incompatible types in assignment of 'const char [1]' to 'char [100]'
sketch_apr11a:71: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:72: error: no match for 'operator+=' in 'Buffer += String(ax, 2u)'
sketch_apr11a:73: error: invalid operands of types 'char [100]' and 'const char [4]' to binary 'operator+'
sketch_apr11a:73: error: in evaluation of 'operator+=(char [100], const char [4])'
sketch_apr11a:74: error: no match for 'operator+=' in 'Buffer += String(ay, 2u)'
sketch_apr11a:75: error: invalid operands of types 'char [100]' and 'const char [4]' to binary 'operator+'
sketch_apr11a:75: error: in evaluation of 'operator+=(char [100], const char [4])'
sketch_apr11a:76: error: no match for 'operator+=' in 'Buffer += String(az, 2u)'
sketch_apr11a:77: error: invalid operands of types 'char [100]' and 'const char [3]' to binary 'operator+'
sketch_apr11a:77: error: in evaluation of 'operator+=(char [100], const char [3])'
sketch_apr11a:79: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:81: error: incompatible types in assignment of 'uint8_t' to 'char [100]'
sketch_apr11a:82: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:83: error: incompatible types in assignment of 'uint8_t' to 'char [100]'
sketch_apr11a:84: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:85: error: incompatible types in assignment of 'uint16_t' to 'char [100]'
sketch_apr11a:86: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:87: error: incompatible types in assignment of 'uint8_t' to 'char [100]'
sketch_apr11a:88: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:89: error: incompatible types in assignment of 'uint8_t' to 'char [100]'
sketch_apr11a:90: error: incompatible types in assignment of 'char' to 'char [100]'
sketch_apr11a:91: error: incompatible types in assignment of 'uint8_t' to 'char [100]'
sketch_apr11a:92: error: incompatible types in assignment of 'char' to 'char [100]'
ecco il codice modificato:
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include "ADXL335.h"
ADXL335 accelerometer;
RTC_DS1307 RTC;
File Dati; // La variabile di tipo file che useremo per il log
const int chipSelect =10;
char Buffer[100];
unsigned long time;
DateTime now = RTC.now(); // leggiamo l'ora
accelerometer.getAcceleration(&ax,&ay,&az);
snprintf(buffer,100,"\t g,%d,%d,%d",ax,ay,az);
void setup ()
{
Serial.begin(9600);
Wire.begin(); // inizializziamo la libreria WIRE per usare
RTC.begin(); //il Real Time clock basato su ds1307
accelerometer.begin();
if (! RTC.isrunning())
{
Serial.println("RTC NON STA FUNZIONANDO");
//LA SEGUENTE ISTRUZIONE SERVE SOLO PER REGOLARE L'OROLOGIO.ATTIVARE SOLO SE NECESSARIO.
// RTC.adjust (DateTime(__DATE__, __TIME__)); //imposta ora e data
}
Serial.print("\nSto verificando la presenza della scheda..\n");
pinMode(10, OUTPUT); // fa funzionare la sdlib
if (!SD.begin(chipSelect))
{
Serial.println("SD card non trovata");
return;
}
else
{
Serial.println("Scheda inserita e funzionante");
Serial.println();
}
}
void loop ()
{
Serial.print ("time:");
time=millis();
Buffer=""; // Nuovo giro, stringa vuota!
float ax,ay,az;
Buffer+=('\t');
Buffer+=String(ax);
Buffer+=" g,";
Buffer+=String(ay);
Buffer+=" g,";
Buffer+=String(az);
Buffer+=" g";
Buffer+=('\t');
Buffer +=(now.day()); // Componiamo la data AAAA/MM/GG
Buffer +=('/');
Buffer +=(now.month());
Buffer +=('/');
Buffer +=(now.year());
Buffer +=('\t');
Buffer +=(now.hour());
Buffer +=(':');
Buffer +=(now.minute());
Buffer +=(':');
Buffer +=(now.second());
Buffer +=('\t'); // tab per separare i campi
Dati = SD.open("datalog.txt", FILE_WRITE); // apriamo il file in scrittura
Serial.println(time);
if (Dati)
{
Dati.println(Buffer); // Scriviamo in un sol colpo i dati sul file
Dati.close(); // chiudiamo e trasferiamo su SD
Serial.print("Dati rilevati \t");
Serial.println(Buffer);
}
else
{
Serial.println("Errore nell'apertura di datalog.txt");
}
delay (0); // cadenza dellascrittura dei dati
}