Hi Folks
I had the blink without delay code working to send results via Serial. I tried to tidy up the code layout and have messed something up.
It should send via serial every 10 seconds (10,000 millis) but it is constantly sending.
I am hoping someone can point to an error that I can understand and work to resolve.
The final program will be used to datalog a battery discharge test, I have tested all the individual components and have had them working with delays but now its time to remove the delays. I can then add in the Datalogger and RTC etc.
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16, 2); // set the LCD address to 0x3f for a 16 chars and 2 line display
int BattPin = A0; // select the input pin for the potentiometer
int BattRawValue; // variable to store the value coming from the pot
int BattVoltCalc; //Variable to store "mapped" result
int BattVolt; // Battery Voltage BattVoltCalc divided by 100
int BattVoltRem; // Battery Volt Calc remainder
//int VPCcalc; // Stores Volts per Cell (BattVolt/12)
int VPC;
int VPCdec;
int VPCrem;
unsigned long LCDcurrentMillis;
unsigned long LCDpreviousMillis = 0; // will store last time LCD was updated
int LCDinterval = 500; // interval at which to update LCD display(milliseconds)
unsigned long currentMillis;
unsigned long DLOGpreviousMillis = 0; // will store last time Datalog was updated
long DLOGinterval = 10000L; // interval at which to update Data Log (milliseconds)
void setup() {
lcd.init(); // Start LCDlcd.init(); // Start LCD
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial) {
// wait for serial port to connect. Needed for native USB port only
}
}
void loop() {
BattRawValue = analogRead(BattPin);
BattVoltCalc = map(BattRawValue, 0, 1023, 0, 3000);
BattVolt = BattVoltCalc / 100;
BattVoltRem = BattVoltCalc % 100;
VPC = BattVoltCalc / 12;
VPCdec = VPC / 100;
VPCrem = VPC % 100;
/* LCDcurrentMillis = millis();
if (LCDcurrentMillis - LCDpreviousMillis >= LCDinterval)
LCDpreviousMillis = LCDcurrentMillis;
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(BattVolt);
lcd.print ('.');
lcd.print(BattVoltRem);
lcd.print("V");
lcd.print(" ");
//lcd.print ('/');
// lcd.print(now.year(), DEC);
// lcd.print (' ');
// lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
//lcd.setCursor(4, 1);
lcd.print(VPCdec);
lcd.print('.');
lcd.print(VPCrem);
lcd.print(" VPC");
lcd.print(now.second(), DEC);
*/
currentMillis = millis();
if (currentMillis - DLOGpreviousMillis >= DLOGinterval)
DLOGpreviousMillis = currentMillis;
Serial.print(BattVolt);
Serial.print(".");
Serial.print(BattVoltRem);
Serial.print("V ");
Serial.print(VPCdec);
Serial.print(".");
Serial.print(VPCrem);
Serial.println("VPC");
}
Thanks in advance