I am back again.
I am inching along with this project of mine. The sketch works fine, but now I am stuck in a loop within a Function. The Function is printing the correct voltage from a voltage divider ( a feat in itself), as it should be, and as you probably figured, I can not escape the loop. I have tried using break; (in various locations), well that is not working.
The error that I am receiving is "exit status 1 expected unqualified-id before 'break'
Sorry about being a pain!!
Thanks again,
The loop is in the "ReadSensors" Function.
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#define NUM_SAMPLES 50 // Voltage - number of samples to take
int sum = 0; // Voltage - sum of samples taken
unsigned char sample_count = 0; // Voltage - current sample number
float voltage = 0.0; // Voltage - calculated voltage
void setup()
{
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm))
if ((tm.Second) == 01) // using Second for testing
{
Serial.println("Second 01 code");
Serial.println();
delay(1000);
SaveDataToPi(); // This function will save the hourly sensor data to the SQLdB on the Raspberry Pi
}
if ((tm.Second) == 55) // using Second for testing
{
Serial.println("Second 55 code");
Serial.println();
delay(1000);
ReadSensors(); // This function will read the sensors for current hourly data
}
else
{
Serial.println("else part of code, ");
Serial.println();
if ((tm.Second) != 01)
delay(1000);
}
}
void ReadSensors() //Read sensor function
{
Serial.println("<<<<< Reading_Sensors >>>>>>");
Serial.println();
// This function will start reading the sensors for current hourly data
{
while (sample_count < NUM_SAMPLES) // add up sample count
{
sum += analogRead(A2);
sample_count++;
}
voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
Serial.print(voltage * 11.132);
Serial.println (" V");
sample_count = 0;
sum = 0;
}
}
void SaveDataToPi() // Save sensor data to Pi dB function
{
Serial.println("<<<<<< Saving_Sensor_Data to the Pi >>>>>>");
Serial.println();
// This function will save the hourly sensor data to the SQLdB on the Raspberry Pi
}