@Hutkikz
Ok.
I got it working!
Had to get the old time library (1.5.0), then it worked perfectly!
The latest time library does not work like that however.
How do I then use it in my code that displays the time?
@Hutkikz
Ok.
I got it working!
Had to get the old time library (1.5.0), then it worked perfectly!
The latest time library does not work like that however.
How do I then use it in my code that displays the time?
It looks like it is not seeing the DS1302 library.
I'm guessing it's because you haven't created an object .
Here is a snippet showing how that's done from the example included with that library:
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
You will have to input the pins that you used.
Edit: didn't see that you replied
Show us your current code.
The reason I asked
is because up till now I've been using another RTC library in my weather station, but now that I've set the time from the compilier, my LCD does not display the correct time (ie. the date is 45/17/2077)
[code]
unsigned long previousMillis = 0;
const long interval = 1;
#include "Full.c"
#include "Draining.c"
#include "Drained.c"
#include "Empty.c"
#include "Charging.c"
#include "nonBlockingDS18B20.h"
enum machineStates {
IDLE, WAITING_FOR_CONVERSION, ABORTED
};
const uint8_t ONE_WIRE_BUS = 2; // Change this to Pin # connected to OneWire bus
const uint8_t RESOLUTION = 12;
const unsigned long maxWaitTime = 5000;
const unsigned long interMeasurementPeriod = 1000;
machineStates currentState;
unsigned long measurementStartTime, measurementStopTime;
unsigned long interMeasurementTimer;
OneWire oneWire(ONE_WIRE_BUS);
nonBlockingDS18B20 tempSensors(&oneWire);
void printAddress(DeviceAddress);
uint8_t numDS18;
#define USE_TOUCH 0x2046
#include <virtuabotixRTC.h> //Libraries needed
virtuabotixRTC myRTC(6, 7, 8);
#include "Adafruit_GFX.h" // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include <SPI.h>
#include <SD.h>
MCUFRIEND_kbv tft; //
#define TFT_BEGIN() tft.begin(0x9488)
#include <XPT2046_Touchscreen.h> // Hardware SPI library
char *name = "Shield XPT2046 Calibration"; //edit name of shield
const int TS_LANDSCAPE = 1; //XPT2046_TouchScreen.h
const int TS_LEFT = 261, TS_RT = 3770, TS_TOP = 3869, TS_BOT = 296;
#define XPT_CS 53 // MEGA2560 SHIELD
#define XPT_IRQ 255 // XPT2046 library does not like IRQ
XPT2046_Touchscreen ts(XPT_CS, XPT_IRQ);
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
bool pressed = ts.touched();
if (pressed) {
TS_Point p = ts.getPoint();
if (TS_LANDSCAPE) mapxy(p.y, p.x);
else mapxy(p.x, p.y);
}
return pressed;
}
void Touch_init(void)
{
ts.begin();
}
void mapxy(int x, int y) //maps ADC to pixel_x, pixel_y
{
int aspect = tft.getRotation(); //LANDSCAPE
int tft_width = tft.width();
int tft_height = tft.height();
switch (aspect & 3) {
case 0: //PORTRAIT
pixel_x = map(x, TS_LEFT, TS_RT, 0, tft_width);
pixel_y = map(y, TS_TOP, TS_BOT, 0, tft_height);
break;
case 1: //LANDSCAPE
pixel_x = map(y, TS_TOP, TS_BOT, 0, tft_width);
pixel_y = map(x, TS_RT, TS_LEFT, 0, tft_height);
break;
case 2: //PORTRAIT REV
pixel_x = map(x, TS_RT, TS_LEFT, 0, tft_width);
pixel_y = map(y, TS_BOT, TS_TOP, 0, tft_height);
break;
case 3: //LANDSCAPE REV
pixel_x = map(y, TS_BOT, TS_TOP, 0, tft_width);
pixel_y = map(x, TS_LEFT, TS_RT, 0, tft_height);
break;
}
}
Adafruit_GFX_Button temp_btn, humidity_btn, home_btn, more_btn;
#define BLACK 0x0000 /* 0, 0, 0 */
#define NAVY 0x000F /* 0, 0, 128 */
#define DARKGREEN 0x03E0 /* 0, 128, 0 */
#define DARKCYAN 0x03EF /* 0, 128, 128 */
#define MAROON 0x7800 /* 128, 0, 0 */
#define PURPLE 0x780F /* 128, 0, 128 */
#define OLIVE 0x7BE0 /* 128, 128, 0 */
#define LIGHTGREY 0xC618 /* 192, 192, 192 */
#define DARKGREY 0x7BEF /* 128, 128, 128 */
#define BLUE 0x001F /* 0, 0, 255 */
#define GREEN 0x07E0 /* 0, 255, 0 */
#define CYAN 0x07FF /* 0, 255, 255 */
#define RED 0xF800 /* 255, 0, 0 */
#define MAGENTA 0xF81F /* 255, 0, 255 */
#define YELLOW 0xFFE0 /* 255, 255, 0 */
#define WHITE 0xFFFF /* 255, 255, 255 */
#define ORANGE 0xFD20 /* 255, 165, 0 */
#define GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define PINK 0xF81F
uint8_t displayScreenNo, prevDay, prevMonth, prevSec, prevMin, prevHour, prevVolt, prevMoon;
uint16_t prevYear;
uint8_t index;
static float prevTemp = 999.99 ; // an unlikely value
float currentTempF = tempSensors.getLatestTempC(index);
String nfm = "";
#define SD_CS 48
#define NAMEMATCH ""
#define PALETTEDEPTH 8 // support 256-colour Palette
char namebuf[32] = "/";
File root;
int pathlen;
void setup() {
//myRTC.setDS1302Time(00, 07, 18, 07, 9, 07, 2022);
Serial.begin(2000000);
numDS18 = tempSensors.begin(RESOLUTION);
if (numDS18 == 0) {
Serial.println(
F("Did not locate any DS-type Temperature Sensors, aborting"));
while (1) {
delay(0);
}
}
TFT_BEGIN();
bool good = SD.begin(SD_CS);
if (!good) {
Serial.print(F("cannot start SD"));
while (1);
}
Touch_init();
tft.setRotation(1); //PORTRAIT
tft.fillScreen(BLACK);
home_btn.initButton(&tft, 440, 280, 80, 80, LIGHTGREY, CYAN, BLACK, "HOME", 2);
home_btn.drawButton(false);
more_btn.initButton(&tft, 440, 40, 80, 80, LIGHTGREY, CYAN, BLACK, "MORE", 2);
more_btn.drawButton(false);
temp_btn.initButton(&tft, 440, 120, 80, 80, LIGHTGREY, CYAN, BLACK, "TEMP", 2);
humidity_btn.initButton(&tft, 440, 200, 80, 80, LIGHTGREY, CYAN, BLACK, "%", 2);
temp_btn.drawButton(false);
humidity_btn.drawButton(false);
tft.setTextSize(3);
}
void loop() {
unsigned int IntensityOfLight;
IntensityOfLight = analogRead(A0);
myRTC.updateTime();
bool down = Touch_getXY();
home_btn.press(down && home_btn.contains(pixel_x, pixel_y));
more_btn.press(down && more_btn.contains(pixel_x, pixel_y));
temp_btn.press(down && temp_btn.contains(pixel_x, pixel_y));
humidity_btn.press(down && humidity_btn.contains(pixel_x, pixel_y));
if (home_btn.justReleased()) {
home_btn.drawButton(true);
more_btn.drawButton();
temp_btn.drawButton();
humidity_btn.drawButton();
}
if (more_btn.justReleased()) {
more_btn.drawButton(true);
home_btn.drawButton();
temp_btn.drawButton();
humidity_btn.drawButton();
}
if (temp_btn.justReleased()) {
home_btn.drawButton();
temp_btn.drawButton(true);
more_btn.drawButton();
humidity_btn.drawButton();
}
if (humidity_btn.justReleased()) {
home_btn.drawButton();
temp_btn.drawButton();
humidity_btn.drawButton(true);
more_btn.drawButton();
}
if (home_btn.justPressed())
{
tft.fillScreen(BLACK);
prevDay = 99;
prevMonth = 99;
prevYear = 9999;
prevHour = 99;
prevMin = 99;
prevSec = 99;
prevTemp = 999.99;
prevVolt = 9.99;
drawHomeScreen();
displayScreenNo = 1;
home_btn.drawButton(true);
temp_btn.drawButton(false);
humidity_btn.drawButton(false);
more_btn.drawButton(false);
}
if (more_btn.justPressed())
{
prevDay = 99;
prevMonth = 99;
prevYear = 9999;
prevHour = 99;
prevMin = 99;
prevSec = 99;
prevTemp = 999.99;
prevVolt = 9.99;
tft.fillScreen(BLACK);
drawMoreScreen();
displayScreenNo = 2;
more_btn.drawButton(true);
temp_btn.drawButton(false);
humidity_btn.drawButton(false);
home_btn.drawButton(false);
}
if (temp_btn.justPressed())
{
prevDay = 99;
prevMonth = 99;
prevYear = 9999;
prevHour = 99;
prevMin = 99;
prevSec = 99;
prevTemp = 999.99;
prevVolt = 9.99;
tft.fillScreen(BLACK);
drawDetailScreenTemp();
displayScreenNo = 3;
temp_btn.drawButton(true);
home_btn.drawButton(false);
humidity_btn.drawButton(false);
more_btn.drawButton(false);
}
if (humidity_btn.justPressed())
{
prevDay = 99;
prevMonth = 99;
prevYear = 9999;
prevHour = 99;
prevMin = 99;
prevSec = 99;
prevTemp = 999.99;
prevVolt = 9.99;
tft.fillScreen(BLACK);
drawDetailScreenHumidity();
displayScreenNo = 4;
humidity_btn.drawButton(true);
temp_btn.drawButton(false);
home_btn.drawButton(false);
more_btn.drawButton(false);
}
switch (displayScreenNo)
{
case 1: drawDynHomeScreen(); break;
case 2: drawDynMoreScreen(); break;
case 3: drawDynDetailScreenTemp(); break;
case 4: drawDynDetailScreenHumidity(); break;
}
}
void drawHomeScreen() {
tft.drawLine(0, 27, 480, 27, LIGHTGREY);
tft.drawLine(0, 28, 480, 28, LIGHTGREY);
tft.drawLine(200, 0, 200, 28, LIGHTGREY);
tft.drawLine(201, 0, 201, 28, LIGHTGREY);
tft.drawLine(0, 288, 480, 288, LIGHTGREY);
tft.drawLine(0, 289, 480, 289, LIGHTGREY);
tft.drawLine(200, 288, 200, 320, LIGHTGREY);
tft.drawLine(201, 289, 201, 320, LIGHTGREY);
}
void drawDetailScreenHumidity() {
tft.drawLine(0, 27, 480, 27, LIGHTGREY);
tft.drawLine(0, 28, 480, 28, LIGHTGREY);
tft.drawLine(200, 0, 200, 28, LIGHTGREY);
tft.drawLine(201, 0, 201, 28, LIGHTGREY);
tft.drawLine(27, 33, 339, 33, LIGHTGREY);
tft.drawLine(27, 59, 339, 59, LIGHTGREY);
tft.drawLine(27, 85, 339, 85, LIGHTGREY);
tft.drawLine(27, 111, 339, 111, LIGHTGREY);
tft.drawLine(27, 137, 339, 137, LIGHTGREY);
tft.drawLine(27, 163, 339, 163, LIGHTGREY);
tft.drawLine(27, 189, 339, 189, LIGHTGREY);
tft.drawLine(27, 215, 339, 215, LIGHTGREY);
tft.drawLine(27, 241, 339, 241, LIGHTGREY);
tft.drawLine(27, 267, 339, 267, LIGHTGREY);
tft.drawLine(27, 293, 339, 293, LIGHTGREY);
tft.drawLine(339, 33, 339, 293, LIGHTGREY);
tft.drawLine(313, 33, 313, 293, LIGHTGREY);
tft.drawLine(287, 33, 287, 293, LIGHTGREY);
tft.drawLine(261, 33, 261, 293, LIGHTGREY);
tft.drawLine(236, 33, 236, 293, LIGHTGREY);
tft.drawLine(209, 33, 209, 293, LIGHTGREY);
tft.drawLine(183, 33, 183, 293, LIGHTGREY);
tft.drawLine(157, 33, 157, 293, LIGHTGREY);
tft.drawLine(131, 33, 131, 293, LIGHTGREY);
tft.drawLine(105, 33, 105, 293, LIGHTGREY);
tft.drawLine(79, 33, 79, 293, LIGHTGREY);
tft.drawLine(53, 33, 53, 293, LIGHTGREY);
tft.drawLine(27, 33, 27, 293, LIGHTGREY);
tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(2, 33);
tft.print("100%");
tft.setCursor(6, 59);
tft.print("90%");
tft.setCursor(6, 85);
tft.print("80%");
tft.setCursor(6, 111);
tft.print("70%");
tft.setCursor(6, 137);
tft.print("60%");
tft.setCursor(6, 163);
tft.print("50%");
tft.setCursor(6, 189);
tft.print("40%");
tft.setCursor(6, 215);
tft.print("30%");
tft.setCursor(6, 241);
tft.print("20%");
tft.setCursor(6, 267);
tft.print("10%");
tft.setCursor(6, 293);
tft.print("0%");
tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(26, 300);
tft.print("6");
tft.setCursor(44, 300);
tft.print("5.5");
tft.setCursor(77, 300);
tft.print("5");
tft.setCursor(96, 300);
tft.print("4.5");
tft.setCursor(128, 300);
tft.print("4");
tft.setCursor(148, 300);
tft.print("3.5");
tft.setCursor(181, 300);
tft.print("3");
tft.setCursor(200, 300);
tft.print("2.5");
tft.setCursor(234, 300);
tft.print("2");
tft.setCursor(253, 300);
tft.print("1.5");
tft.setCursor(285, 300);
tft.print("1");
tft.setCursor(305, 300);
tft.print("0.5");
tft.setCursor(337, 300);
tft.print("0");
}
void drawMoreScreen() {
more_btn.drawButton(true);
}
void drawDetailScreenTemp() {
tft.drawLine(0, 27, 480, 27, LIGHTGREY);
tft.drawLine(0, 28, 480, 28, LIGHTGREY);
tft.drawLine(200, 0, 200, 28, LIGHTGREY);
tft.drawLine(201, 0, 201, 28, LIGHTGREY);
tft.drawLine(27, 33, 339, 33, LIGHTGREY);
tft.drawLine(27, 59, 339, 59, LIGHTGREY);
tft.drawLine(27, 85, 339, 85, LIGHTGREY);
tft.drawLine(27, 111, 339, 111, LIGHTGREY);
tft.drawLine(27, 137, 339, 137, LIGHTGREY);
tft.drawLine(27, 163, 339, 163, LIGHTGREY);
tft.drawLine(27, 189, 339, 189, LIGHTGREY);
tft.drawLine(27, 215, 339, 215, LIGHTGREY);
tft.drawLine(27, 241, 339, 241, LIGHTGREY);
tft.drawLine(27, 267, 339, 267, LIGHTGREY);
tft.drawLine(27, 293, 339, 293, LIGHTGREY);
tft.drawLine(339, 33, 339, 293, LIGHTGREY);
tft.drawLine(313, 33, 313, 293, LIGHTGREY);
tft.drawLine(287, 33, 287, 293, LIGHTGREY);
tft.drawLine(261, 33, 261, 293, LIGHTGREY);
tft.drawLine(236, 33, 236, 293, LIGHTGREY);
tft.drawLine(209, 33, 209, 293, LIGHTGREY);
tft.drawLine(183, 33, 183, 293, LIGHTGREY);
tft.drawLine(157, 33, 157, 293, LIGHTGREY);
tft.drawLine(131, 33, 131, 293, LIGHTGREY);
tft.drawLine(105, 33, 105, 293, LIGHTGREY);
tft.drawLine(79, 33, 79, 293, LIGHTGREY);
tft.drawLine(53, 33, 53, 293, LIGHTGREY);
tft.drawLine(27, 33, 27, 293, LIGHTGREY);
tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(6, 33);
tft.print("45");
tft.print((char)247);
tft.setCursor(6, 59);
tft.print("40");
tft.print((char)247);
tft.setCursor(6, 85);
tft.print("35");
tft.print((char)247);
tft.setCursor(6, 111);
tft.print("30");
tft.print((char)247);
tft.setCursor(6, 137);
tft.print("25");
tft.print((char)247);
tft.setCursor(6, 163);
tft.print("20");
tft.print((char)247);
tft.setCursor(6, 189);
tft.print("15");
tft.print((char)247);
tft.setCursor(6, 215);
tft.print("10");
tft.print((char)247);
tft.setCursor(6, 241);
tft.print(" 5");
tft.print((char)247);
tft.setCursor(6, 267);
tft.print(" 0");
tft.print((char)247);
tft.setCursor(6, 285);
tft.print("-5");
tft.print((char)247);
tft.setTextSize(1);
tft.setTextColor(LIGHTGREY);
tft.setCursor(26, 300);
tft.print("6");
tft.setCursor(44, 300);
tft.print("5.5");
tft.setCursor(77, 300);
tft.print("5");
tft.setCursor(96, 300);
tft.print("4.5");
tft.setCursor(128, 300);
tft.print("4");
tft.setCursor(148, 300);
tft.print("3.5");
tft.setCursor(181, 300);
tft.print("3");
tft.setCursor(200, 300);
tft.print("2.5");
tft.setCursor(234, 300);
tft.print("2");
tft.setCursor(253, 300);
tft.print("1.5");
tft.setCursor(285, 300);
tft.print("1");
tft.setCursor(305, 300);
tft.print("0.5");
tft.setCursor(337, 300);
tft.print("0");
}
void battery () {
int sensor = analogRead(A1);
//Serial.println(sensor);
float voltage = (sensor * 5.0) / 1023;
//Serial.println(voltage);
if (voltage > 3.65) {
tft.drawRGBBitmap(355, 3, Charging, 36, 21);
}
if ((voltage <= 3.60) && (voltage > 3.20)) {
tft.drawRGBBitmap(355, 3, Full, 36, 21);
}
if ((voltage <= 3.20) && (voltage > 2.80)) {
tft.drawRGBBitmap(355, 3, Draining, 36, 21);
}
if ((voltage <= 2.80) && (voltage > 2.40)) {
tft.drawRGBBitmap(355, 3, Drained, 36, 21);
}
if (voltage <= 2) {
tft.drawRGBBitmap(355, 3, Empty, 36, 21);
}
}
void buttons () {
home_btn.drawButton(false);
more_btn.drawButton(false);
temp_btn.drawButton(false);
humidity_btn.drawButton(false);
}
void drawDynHomeScreen() {
tft.setTextSize(3);
tft.setTextColor(WHITE);
if (myRTC.dayofmonth != prevDay)
{
prevDay = myRTC.dayofmonth;
tft.fillRect(5, 3, 33, 21, BLACK);
tft.setCursor(5, 3);
if (myRTC.dayofmonth < 10)
{
moonPhase();
tft.print("0");
tft.print(myRTC.dayofmonth);
}
else
{
moonPhase();
tft.print(myRTC.dayofmonth);
}
}
tft.setCursor(41, 3);
tft.print("/");
if (myRTC.month != prevMonth)
{
prevMonth = myRTC.month;
tft.fillRect(59, 3, 33, 21, BLACK);
tft.setCursor(59, 3);
if (myRTC.month < 10) {
tft.print("0");
tft.print(myRTC.month);
}
else {
tft.print(myRTC.month);
}
}
tft.setCursor(95, 3);
tft.print("/");
if (myRTC.year != prevYear)
{
prevYear = myRTC.year;
tft.fillRect(113, 3, 70, 21, BLACK);
tft.setCursor(113, 3);
tft.print(myRTC.year);
}
if (myRTC.hours != prevHour)
{
prevHour = myRTC.hours;
tft.fillRect(206, 3, 33, 21, BLACK);
tft.setCursor(206, 3);
if (myRTC.hours < 10) {
tft.print("0");
tft.print(myRTC.hours);
}
else {
tft.print(myRTC.hours);
}
}
tft.setCursor(239, 3);
tft.print(":");
if (myRTC.minutes != prevMin)
{
prevMin = myRTC.minutes;
tft.fillRect(256, 3, 33, 21, BLACK);
tft.setCursor(256, 3);
if (myRTC.minutes < 10) {
tft.print("0");
tft.print(myRTC.minutes);
}
else {
tft.print(myRTC.minutes);
}
}
tft.setCursor(290, 3);
tft.print(":");
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (myRTC.seconds != prevSec)
{
prevSec = myRTC.seconds;
tft.fillRect(306, 3, 33, 21, BLACK);
tft.setCursor(306, 3);
if (myRTC.seconds < 10) {
tft.print("0");
tft.print(myRTC.seconds);
Serial.print("0");
Serial.println(myRTC.seconds);
}
else {
tft.print(myRTC.seconds);
Serial.println(myRTC.seconds);
}
}
}
int sensor = analogRead(A1);
float voltage = (sensor * 5.0) / 1023;
if (voltage != prevVolt)
{
prevVolt = voltage;
battery();
}
uint8_t index;
static uint32_t loopCount = 0;
currentMillis = millis();
switch (currentState) {
case WAITING_FOR_CONVERSION:
if (tempSensors.isConversionDone()) {
// Measurement has finished print results
measurementStopTime = currentMillis;
Serial.print(F(" Sensors Took: "));
Serial.print(measurementStopTime - measurementStartTime);
Serial.println(F(" ms"));
Serial.print(loopCount);
Serial.println(F(" Iterations of loop occurred during this period."));
// Print measurements from all temperature sensors
for (index = 0; index < numDS18; index++) {
Serial.print(F(" Results: "));
Serial.print(tempSensors.getLatestTempC(index), 2);
Serial.println(F(" (C)"));
if (currentTempF != prevTemp)
{
Serial.print(F("Temp values "));
Serial.print(prevTemp);
Serial.print(F(" "));
Serial.print(currentTempF);
Serial.print(F(" "));
prevTemp = tempSensors.getLatestTempC(index);
Serial.println(prevTemp);
tft.setCursor(5, 294);
tft.fillRect(5, 294, 190, 21, BLACK);
tft.print(tempSensors.getLatestTempC(index), 2);
tft.print(" ");
tft.print((char)247);
tft.print("C");
}
}
// Hang out until time for next measurement
currentState = IDLE;
interMeasurementTimer = currentMillis;
} else if (currentMillis - measurementStartTime >= maxWaitTime) {
Serial.println(F("Timed Out Waiting for Measurements to Complete -- Aborting"));
currentState = ABORTED;
}
break;
case IDLE:
// Check if it's time to start another measurement
if (currentMillis - interMeasurementTimer >= interMeasurementPeriod) {
currentState = WAITING_FOR_CONVERSION;
loopCount = 0;
// Kick off another set of non-blocking sensor readings
measurementStartTime = currentMillis;
if (!tempSensors.startConvertion()) {
Serial.println(F("Failed to Start Conversion Cycle, Aborting"));
currentState = ABORTED;
}
}
break;
case ABORTED:
break;
}
loopCount++;
}
void drawDynDetailScreenHumidity() {
myRTC.updateTime();
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(5, 3);
if (myRTC.dayofmonth < 10)
{
tft.print("0");
tft.print(myRTC.dayofmonth);
}
else
{
tft.print(myRTC.dayofmonth);
}
tft.print("/");
if (myRTC.month < 10) {
tft.print("0");
tft.print(myRTC.month);
}
else {
tft.print(myRTC.month);
}
tft.print("/");
tft.print(myRTC.year);
tft.setCursor(206, 3);
if (myRTC.hours < 10) {
tft.print("0");
tft.print(myRTC.hours);
}
else {
tft.print(myRTC.hours);
}
tft.print(":");
if (myRTC.minutes < 10) {
tft.print("0");
tft.print(myRTC.minutes);
}
else {
tft.print(myRTC.minutes);
}
int sensor = analogRead(A1);
float voltage = (sensor * 5.0) / 1023;
if (voltage != prevVolt)
{
prevVolt = voltage;
battery();
}
}
void drawDynMoreScreen() {
buttons();
}
void drawDynDetailScreenTemp() {
myRTC.updateTime();
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(5, 3);
if (myRTC.dayofmonth < 10)
{
tft.print("0");
tft.print(myRTC.dayofmonth);
}
else
{
tft.print(myRTC.dayofmonth);
}
tft.print("/");
if (myRTC.month < 10) {
tft.print("0");
tft.print(myRTC.month);
}
else {
tft.print(myRTC.month);
}
tft.print("/");
tft.print(myRTC.year);
tft.setCursor(206, 3);
if (myRTC.hours < 10) {
tft.print("0");
tft.print(myRTC.hours);
}
else {
tft.print(myRTC.hours);
}
tft.print(":");
if (myRTC.minutes < 10) {
tft.print("0");
tft.print(myRTC.minutes);
}
else {
tft.print(myRTC.minutes);
}
int sensor = analogRead(A1);
float voltage = (sensor * 5.0) / 1023;
if (voltage != prevVolt)
{
prevVolt = voltage;
battery();
}
}
[/code]
That's the code for the other library. Show us your attempt at the code using the library you want to use.
@Hutkikz
I was hoping I could set it with one library, then read it with the other one.
Is that not going to work?
I don;t think so but you could try it ![]()
This project has complete code to set the clock from operator input. The last step is synch that you can hit to a fraction of a second.
@Hutkikz
That's what I did, but it displays impossible dates, so I guess it won't work.
To begin with, I uploaded the DS1302 library Serial example, and it says that the time has not been set.
Serial monitor:
DS1302RTC Read Test
RTC module activated
The DS1302 is stopped. Please run the SetTime
example to initialize the time and begin running.The DS1302 is write protected. This normal.
I'm not sure why the first line is bold, sorry.
@madmark2150
That uses yet another library.
Is the Battery good? when it is set does it keep time after power to the arduino has been removed?
The setting code is independent of library. Lift the time set logic and just substitute the driver of your choice. The operation of them is the same at this level.
Hmmm, once set it should remain set unless it's battery is removed/dead.
Hmmm, once set it should remain set unless it's battery is removed/dead.
@Hutkikz
That's kinda what I thought.
@madmark2150
Your code displays too many errors, which I'm not repairing unless I have to.
@Hutkikz
It stays set with the library I originally used.
It compiles and runs flawlessly for me ...
Did you change it to my library (post #33)?
I have figured out how to get it within half a second of the real time. I tell the RTC a time two minutes ahead of time, then reset two seconds before my computer displays that exact time. It then displays within half a second of the real time.
(I also then comment out the line that sets the time so it doesn't reset every time the board does)
Thanks everyone for your help!!