Hi,
I´ve got a strange problem with digitalWrite.
I set the latch named pin to HIGH using digitalWrite, but it stays LOW.
Here´s the code:
#include <Wire.h>
#include "RTClib.h"
int hourplus = 12;
int minplus = 11;
int mrshiftreset = 4;
int datapin = 5;
int clockpin = 6;
int latch = 7;
int onboardled = 13;
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
pinMode(hourplus, INPUT);
digitalWrite(hourplus, HIGH);
pinMode(minplus, INPUT);
digitalWrite(minplus, HIGH);
pinMode(mrshiftreset, OUTPUT);
digitalWrite(mrshiftreset, LOW);
digitalWrite(mrshiftreset, HIGH);
pinMode(datapin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(onboardled, OUTPUT);
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(digitalRead(mrshiftreset));
Serial.print(digitalRead(datapin));
Serial.print(digitalRead(clockpin));
Serial.print(digitalRead(latch));
Serial.println();
digitalWrite(latch, HIGH);
Serial.print(digitalRead(hourplus));
Serial.print(digitalRead(minplus));
Serial.println();
if(!digitalRead(hourplus))
{
RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour()+1,now.minute(),0));
delay(300);
if(now.hour() >= 24)
{
RTC.adjust(DateTime(now.year(),now.month(),now.day(),0,now.minute(),0));
}
}
if(!digitalRead(minplus))
{
RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour(),now.minute()+1,0));
delay(300);
if(now.minute() >= 60)
{
RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour(),0,0));
}
}
if(now.second()%5 == 0)
{
digitalWrite(onboardled, HIGH);
}
else
{
digitalWrite(onboardled, LOW);
}
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
delay(500);
}
And here is the Serial Output:
1000
11
4:45:41
1000
11
4:45:42
1000
11
4:45:42
1000
11
4:45:43
DigitalWrite with the onboard Led works fine.
Has anyone an idea?
greetings
Alex