hi
here is my code will get the sensor values from defined pins and stores in .csv file
when i try to print the values in a file through a function it is not happening can any one check out my function
#include<LiquidCrystal.h>
#include<SD.h>
#include<SPI.h>
#include <Wire.h>
#include "RTClib.h"
#define RED 6
#define GREEN 7
#define BLUE 8
#define buttonPin1 16 //Analog pin A2 Reff
#define SS 10
LiquidCrystal lcd(14, 15, 5, 4, 3, 2); // sets the interfacing pins 14-A0(RS), 15-A1(E)
Sd2Card card; SdVolume volume; SdFile root; // set up variables using the SD utility library functions:
File logFile;
RTC_DS1307 rtc;
void setup() {
pinMode(RED, INPUT); pinMode(GREEN, INPUT); pinMode(BLUE, INPUT);
pinMode(buttonPin1, INPUT_PULLUP);
int buttonState1, buttonState2;
Serial.begin(9600);
Wire.begin();
rtc.begin();
lcd.begin(16, 2); // initializes the 16x2 LCD
Check();
DateTime now = rtc.now();// Checks the SDcard RTC is present or not
String U = String(now.unixtime());
String Filename = Unixfile(U); Serial.print("Filename:"); Serial.print(Filename); // Creates the UnixTime as a Filename
logFile = SD.open(Filename, FILE_WRITE);
logFile.print(U); logFile.print("\n"); logFile.flush();
logFile.print("RReffTP"); logFile.print(","); logFile.print("GReffTP"); logFile.print(","); logFile.print("BReffTP\n"); logFile.flush();
while (1)
{
buttonState1 = digitalRead(buttonPin1);
double REDAbsorption, GREENAbsorption, BLUEAbsorption;
double tpReffR[30], tpReffG[30], tpReffB[30];
double tpSampleR, tpSampleG, tpSampleB;
if (buttonState1 == LOW)
{
for (int i = 0; i < 30; i++)
{
tpReffR[i] = pulseIn(RED, LOW, 10000) * 2; tpReffG[i] = pulseIn(GREEN, LOW, 10000) * 2; tpReffB[i] = pulseIn(BLUE, LOW, 10000) * 2;
Serial.print("\ntpReffR "); Serial.print(tpReffR[i]);
delay(10);
}
delay(500);
printfile(tpReffR, tpReffG, tpReffB, 30);
buttonState1 == HIGH;
}
}
}
//**************************************************************************************************************************************************************************
void printfile(double *R, double *G, double *B, int Len)
{
logFile.print("function testing"); logFile.flush();
Serial.print("\n function; ");
for (int i = 0; i < Len; i++)
{
Serial.println(R[i]); logFile.flush();
}
Serial.print("Done.....");
}
//********************************************************************************************************************************************************************
void Check()
{
DateTime now = rtc.now();
if ((!SD.begin(SS)) || (!rtc.isrunning()))
{
lcd.setCursor(0, 0); lcd.print("Insert SDcard or"); Serial.println("Insert SDcard or");
lcd.setCursor(0, 1); lcd.print("Check RTC "); Serial.println("Check RTC");
//delay(1000);
exit (0);
}
else
lcd.setCursor(0, 0); lcd.print(" "); lcd.setCursor(0, 1); lcd.print(" ");
lcd.setCursor(0, 0); lcd.print("SDCard Present "); lcd.setCursor(0, 1); lcd.print("RTC is Working "); delay(1000);
}
//*******************************************************************************************************************************************************************
String Unixfile(String U)
{
char Name[12] = {0};
for (int i = 0; i < 7; i++)
{
Name[i] = U[i];
}
Name[7] = '.';
for (int i = 7; i < 10; i++)
{
Name[i + 1] = U[i];
}
lcd.setCursor(0, 0); lcd.print("UTC: "); lcd.print(U); lcd.setCursor(0, 1); lcd.print("File:"); lcd.print(Name); delay(1000);
lcd.setCursor(0, 0); lcd.print(" "); lcd.setCursor(0, 1); lcd.print(" ");
return Name;
}
//******************************************************************************************************************************************************************
void loop()
{}