I am currently working on my Year 12 Design and Technology major project and am making a clock from an arduino that uses light. I am using a DS3231 RTC module and the code I have is not working for some reason. I want the code to allow the LED to be off the whole time and only come on when I want it to at a specific time, fade out and then turn on again the following day. Could someone please go through the code I'm using and see if I need to change anything and get some help?
Thanks
#include <DS3231.h> //Include the clock library
// Changable Vars
int fadeTime = 1; // How long the light will fade to max
int setHour = 15; // Set hours to wake (military time)
int setMin = 30; // Set minute to wake
int uled = 9; // Set pinout with with PWM
// Set up Vars
DS3231 rtc(SDA, SCL);
Time t;
void start();
void setup()
{
pinMode(uled, OUTPUT);
Serial.begin(9600); // Match to serial monitor
rtc.begin();
}
void loop()
{
t = rtc.getTime(); // Make a time class called 't'
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
if (t.hour == setHour && t.min == setMin) // Check if it's time to wake up!
{
start();
}
// Wait one second before repeating
delay (1000);
}
void start()
{
// Fix for SB LED
analogWrite(uled, 1);
delay((fadeTime * 60000)/50);
analogWrite(uled, 2);
delay((fadeTime * 60000)/50);
analogWrite(uled, 3);
delay((fadeTime * 60000)/50);
analogWrite(uled, 4);
delay((fadeTime * 60000)/50);
analogWrite(uled, 4);
delay((fadeTime * 60000)/50);
analogWrite(uled, 5);
delay((fadeTime * 60000)/50);
// Fade script
for (int i = 6 ; i <= 255; i++)
{
analogWrite(uled, i);
delay(((fadeTime * 60000)/306));
Serial.print(" mil sec ");
Serial.print(((fadeTime * 60000)/306));
Serial.print(" PWM " );
Serial.print(i);
}
delay(20000); // Stay Bright
analogWrite(uled, 0); // Turn off
}
This is the video I used to help me set up the arduino, I followed it exactly and it does not turn on and then off how I want it to