Hi,
I'm trying to get a program running on Arduino Uno, my goal is to have 3 led (one red one blue and one green) that will light up only at certain times on the days using a RTC module.
The red one should be on between 20:00 and 6:29 then it should be off
The blue one should be on between 6:30 and 7:29 and then should turn off
Finally the green one should be on between 7:30 and 8:59
After that they should all be off during the rest of the day and start again at 20:00.
I've managed to do the wiring and the RTC seems to work but the leds just won't do what I want and I can't find my mistake.
Thank you for any help you could get me, here's what I've got so far:
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(6, 7, 8);
const int ledPinRed = 13;
const int ledPinBlue = 12;
const int ledPinGreen = 11;
void setup()
{
Serial.begin(9600);
myRTC.setDS1302Time(30, 29, 15, 7, 5, 6, 2022); // seconds, minutes, hours, day of the week, day of the month, month, year
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinBlue, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(A0, INPUT);
pinMode(10, OUTPUT);
}
void loop()
{
myRTC.updateTime();
Serial.print("Current Date / Time: ");
Serial.print(myRTC.dayofmonth);
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
delay(500); // Delay so the program doesn't print non-stop
if (myRTC.hours>=20 or myRTC.hours<6)
{
digitalWrite(ledPinRed, HIGH);
digitalWrite(ledPinBlue, LOW);
digitalWrite(ledPinGreen, LOW);
}
if (myRTC.hours=6 and myRTC.minutes<30)
{
digitalWrite(ledPinRed, HIGH);
digitalWrite(ledPinBlue, LOW);
digitalWrite(ledPinGreen, LOW);
}
if (myRTC.hours=6 or myRTC.hours>=30)
{
digitalWrite(ledPinRed, LOW);
digitalWrite(ledPinBlue, HIGH);
digitalWrite(ledPinGreen, LOW);
}
if (myRTC.hours=7 and myRTC.minutes<30)
{
digitalWrite(ledPinRed, LOW);
digitalWrite(ledPinBlue, HIGH);
digitalWrite(ledPinGreen, LOW);
}
if (myRTC.hours=7 and myRTC.minutes>=30)
{
digitalWrite(ledPinRed, LOW);
digitalWrite(ledPinBlue, LOW);
digitalWrite(ledPinGreen, HIGH);
}
if (myRTC.hours=8)
{
digitalWrite(ledPinRed, LOW);
digitalWrite(ledPinBlue, LOW);
digitalWrite(ledPinGreen, HIGH);
}
if (myRTC.hours>=9 and myRTC.hours <20)
{
digitalWrite(ledPinRed, LOW);
digitalWrite(ledPinBlue, LOW);
digitalWrite(ledPinGreen, LOW);
}
}
mouellou