i have some problem for my coding...
after i connect it with my circuit, the program was not function well..
the reverse motor1 and the motor2 is not running...
can anyone help me with my coding...
my program is about smart feeder. at 8.30am and 5.30 the food container will open (control by motor1 and limit switch) the the food from tank will fill the container when motor2 run about 30sec. the after a few min, the container will closed until the next feeding time...
this is my coding
//include lcd library
#include <LiquidCrystal.h>
int motor1a = 12;
int motor1b = 13;
int motor2a = 11;
int motor2b = 10;
int limit1 = A0;
int limit2 = A1;
//create object
//lcd(RS, E, D4,D5,D6,D7);
LiquidCrystal lcd(2,3,4,5,6,7);
const int backlight =13;
//const int buttonHr = 4; //digital pin used as hour adjustment input
//const int buttonMin = 4; //digital pin used as min adjustment input
int secs =0;
int secs2 = 0;
int mins = -1;
int hrs = 0;
boolean isAM = true;
int hrtimer1 = 8;
int mintimer1 = 30;
int hrtimer2 = 5;
int mintimer2 = 30;
int milliDivSecs = 1000;
int milliDivMins = 60000;
int milliDivHrs = 360000;
unsigned long prevmillis=0;
int interval = 1000;
void setup(){
pinMode(backlight, OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(limit1,OUTPUT);
pinMode(limit2,OUTPUT);
// pinMode(buttonHr, INPUT);
// pinMode(buttonMin, INPUT);
digitalWrite(motor1a,LOW);
digitalWrite(motor1b,LOW);
digitalWrite(motor2a,LOW);
digitalWrite(motor2b,LOW);
digitalWrite(backlight, HIGH);
lcd.begin(16,2); //set number of cols and rows
//print out LCD clock duisplay
lcd.setCursor(5,0);
lcd.print("03:50:00 PM");
Serial.begin(9600);
}
void loop(){
unsigned long currmillis = millis();
if(currmillis-prevmillis > 999){
//lcd.clear();
prevmillis =currmillis;
if(secs<10){
lcd.setCursor(12,0);
lcd.print(secs);
lcd.setCursor(11,0);
lcd.print(0);
}
else{
lcd.setCursor(11,0);
lcd.print(secs);
}
//display minutes
if(secs == 0){
mins = mins+1;
updateMin();
}
//get new seconds from system time
secs = (millis()/milliDivSecs)%60; // divide by 1000 and mod by 60 gives seconds from milliseconds
if (hrs == hrtimer1 && mins == mintimer1)
{
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
while(digitalRead(limit1) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
digitalWrite(motor2a,1);
digitalWrite(motor2b,0);
delay(30000);
digitalWrite(motor2a,0);
digitalWrite(motor2b,0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
while(digitalRead(limit2) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
}
if (hrs == hrtimer2 && mins == mintimer2)
{
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
while(digitalRead(limit1) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
digitalWrite(motor2a,1);
digitalWrite(motor2b,0);
delay(30000);
digitalWrite(motor2a,0);
digitalWrite(motor2b,0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
while(digitalRead(limit2) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
}
/*
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
delay(3000);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
delay(3000);
*/
}
}
//update min function
//calls the update am apm funciton and the update hours functions.
void updateMin(){
if(mins > 59){
hrs = hrs+1;
updateHrs(); //update hours then
if(hrs==11 && mins >59){
updateAMPM();
}
mins = 0; //reset mins
lcd.setCursor(8,0);
lcd.print("00");
}
if(mins < 10){
lcd.setCursor(9,0);
}
else{
lcd.setCursor(8,0);
}
lcd.print(mins);
}
//update hour function
void updateHrs(){
//display hours - needs fixing for am pm
if(hrs> 12){
//reset to 1
hrs = 1;
}
if(hrs< 10){
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(6,0);
}
else{
lcd.setCursor(5,0);
}
lcd.print(hrs);
}
void updateAMPM(){
if(isAM){
isAM = false;
lcd.setCursor(14,0);
lcd.print("PM");
}
else{
isAM = true;
lcd.setCursor(14,0);
lcd.print("AM");
}
}