Hi All
I working on a timed based project that at a certain time i need to read A1 and turn the the led on.
I have the code working but need some explanation why my first code did not work proberly, time functions working using ds1703 module.
First Code only prints Serial but does not read A1 at set time:
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 RTC;
void setup () {
Wire.begin();
RTC.begin();
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
// following line sets the RTC to the date & time this sketch was compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(' ');
if (now.hour() < 10)
Serial.print('0');
Serial.print(now.hour(), DEC);
Serial.print(':');
if (now.minute() < 10)
Serial.print('0');
Serial.print(now.minute(), DEC);
Serial.print(':');
if (now.second() < 10)
Serial.print('0');
Serial.print(now.second(), DEC);
Serial.println();
delay(100);
// Serial.println(" It is time to report !! ");
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
//Timer1
if ( ( now.hour() == 19 ) && ( now.minute() == 20 ) )
{
// Serial.println(" It is time to report !! ");
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
if (voltage >= 1);
Serial.println(voltage);
digitalWrite(7, HIGH);
}
else
{
digitalWrite(7, LOW);
}
SECOND CODE works well:
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
if ( ( now.hour() == 20 ) && ( now.minute() == 44 ) && (voltage >= 1))
{
digitalWrite(7, HIGH);
}
else
{
digitalWrite(7, LOW);
}
}
Any info would be app.
Thanks