Need help with code. Using UNO R3. its simple 24 hrs loop. for chicken feed, opens 3 times in 24hrs at different delay time. open/close time 6seconds.
after 24 hrs it adds total of 114 seconds (-/+1sec).
// defines pins
#define stepPin 13
#define dirPin 12
#define enbPin 11
#define belPin 8
#define SECOND 1000UL
#define MINUTE (SECOND * 60UL)
#define HOUR (MINUTE * 60UL)
void setup() {
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enbPin,OUTPUT);
pinMode(belPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH);
for(int x = 0; x < 3000; x++) {
digitalWrite(belPin,HIGH);
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
digitalWrite(belPin,LOW);
}
delay((MINUTE*20)-(SECOND*6));
digitalWrite(dirPin,LOW);
for(int x = 0; x < 3000; x++) {
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
}
delay(((HOUR*5)+(MINUTE*40))-(SECOND*6));
digitalWrite(dirPin,HIGH);
for(int x = 0; x < 3000; x++) {
digitalWrite(belPin,HIGH);
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
digitalWrite(belPin,LOW);
}
delay((MINUTE*15)-(SECOND*6));
digitalWrite(dirPin,LOW);
for(int x = 0; x < 3000; x++) {
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
}
delay(((HOUR*13)+(MINUTE*45))-(SECOND*6));
digitalWrite(dirPin,HIGH);
for(int x = 0; x < 3000; x++) {
digitalWrite(belPin,HIGH);
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
digitalWrite(belPin,LOW);
}
delay((MINUTE*30)-(SECOND*6));
digitalWrite(dirPin,LOW);
for(int x = 0; x < 3000; x++) {
digitalWrite(enbPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
digitalWrite(enbPin,HIGH);
}
delay(((HOUR*3)+(MINUTE*30))-(SECOND*6));
}