I'm developing a program (with helping in Forum) to alarm two led with RTC from (min:second) to (min:second) with Serial Monitor but I succeeded only to do that for one led.
when I write the code for twice, the first led turns off and the other receive the command ...
briefly ... Two led don't set together
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
int start_minute;
int start_second;
int end_minute;
int end_second;
int type;
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
}
//Any pin. I have used Pin 4
pinMode(12, OUTPUT);
}
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();
Serial.println();
delay(1000);
int second_of_the_hour = now.minute() * 60 + now.second();
//The time is set as 24 hours
//Pin 4 get high at 6pm and low at 6am
if (Serial.available() > 0)
{
type = Serial.parseInt
start_minute = Serial.parseInt();
start_second = Serial.parseInt();
end_minute = Serial.parseInt();
end_second = Serial.parseInt();
}
int start_time = start_minute * 60 + start_second;
int end_time = end_minute * 60 + end_second;
if (type =5 && second_of_the_hour >= start_time && second_of_the_hour < end_time)
{
if (!digitalRead(12))
{
digitalWrite(12, HIGH);
Serial.println("ON");
}
}
else if (digitalRead(12))
{
digitalWrite(12, LOW);
Serial.println("OFF");
}
if (type =6 && second_of_the_hour >= start_time && second_of_the_hour < end_time)
{
if (!digitalRead(8))
{
digitalWrite(8, HIGH);
Serial.println("ON");
}
}
else if (digitalRead(8))
{
digitalWrite(8, LOW);
Serial.println("OFF");
}
}
4 != 12.
If you expect to have 2 LEDs connected, you need 2 output pins.
sorry that is small mistake .. I write it well in code.
if (type =5
Why are you assigning 5 to type in an if statement?
I typed it to set led 12 ON
example : 5,43,12,45,6 .. turn on led 12 from (43:12) to (45:6)
and 6 for led 8 ..
I can't make them work together (every led) with its time ..
You have not added any more Serial.print() statements, to show that type, start_minute, start_second, end_minute, and end_second contain valid values. Why not?
You haven't proven that start_time and end_time contain valid values. Why not?