Hi guys,
Can someone please look into my code and say did I doo something wrong there?
I'm trying to automate aquarium light dimming, everything works except every two days clock starts counting from zero, and i think its around 14:30 every time, not so sure.
#include <Stepper.h>
#include <virtuabotixRTC.h> //Library used
const int stepsPerRevolution = 1050;
int curentStep =0;
bool radi = true;
// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 2, 7, 3, 8);
virtuabotixRTC myRTC(11, 12, 13);
int sun;
void setup() {
pinMode(4, OUTPUT);
//myRTC.setDS1302Time(5, 49, 19, 3, 12, 1, 2024);
// seconds, minutes, hours, day of the week, day of the month, month, year
myStepper.setSpeed(10);
Serial.begin(9600);
}
void loop() {
myRTC.updateTime();
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
if ((myRTC.hours >= 8) && (myRTC.hours < 10) ){
if(myRTC.seconds == 0 || myRTC.seconds == 20 || myRTC.seconds == 40 ){
if(radi == true){
if(curentStep < 360){
curentStep += 1;
myStepper.step(1);
Serial.print("step is: ");
Serial.println(curentStep);
}
}
}
sun = 1;
}
else if((myRTC.hours >= 10) && (myRTC.hours < 13)){
if(myRTC.seconds == 0 || myRTC.seconds == 10 || myRTC.seconds == 20 || myRTC.seconds == 30 || myRTC.seconds == 40 || myRTC.seconds == 50 || myRTC.seconds == 55 ){
if(radi == true){
if(curentStep < 1050){
curentStep += 1;
myStepper.step(1);
Serial.print("step is: ");
Serial.println(curentStep);
}
else{
digitalWrite(4, HIGH);
}
}
}
sun = 2;
}
else if((myRTC.hours >= 15) && (myRTC.hours < 17)){
if(myRTC.seconds == 0 || myRTC.seconds == 10 || myRTC.seconds == 20 || myRTC.seconds == 30 || myRTC.seconds == 40 || myRTC.seconds == 50 ){
if(radi == true){
digitalWrite(4, LOW);
if(curentStep >360){
curentStep -= 1;
myStepper.step(-1);
Serial.print("step is: ");
Serial.println(curentStep);
}
}
}
sun = 3;
}
else if((myRTC.hours >= 17) && (myRTC.hours < 20)){
if(myRTC.seconds == 0 || myRTC.seconds == 20 || myRTC.seconds == 40 ){
if(radi == true){
if(curentStep >0){
curentStep -= 1;
myStepper.step(-1);
Serial.print("step is: ");
Serial.println(curentStep);
}
}
}
sun = 4;
}
else{
sun = 0;
}
delay(500);
radi = !radi;
}
