i building automatic dog feeder final project engineering degree. have 12v dc motor turns auger distributes food bowl. not standard @ on writing code. give me code please? need come on @ time each day possibly using millis function?. once work, can adjust run time , speed right amount of food pushed out bowl. lost here , it's crunch time.
thanks again,
jason
thanks again,
jason
i'm sure come "use time library", this:
code: [select]
unsigned long currentmicros;
unsigned long previousmicros;
unsigned long elapsedtime;
byte hundredths;
byte tenths;
byte secondsones;
byte oldsecondsones;
byte secondstens;
byte minutesones;
byte minutestens;
byte hoursones;
byte hourstens;
void setup(){
serial.begin(115200); // make serial monitor match
serial.println (setup done");
}
void loop(){
currentmicros = micros();
// how long's been?
elapsedtime = currentmicros - previousmicros;
if ( elapsedtime >=10000ul){ // 0.01 second passed? update timers
previousmicros = previousmicros + 10000ul;
hundredths = hundredths+1;
if (hundredths == 10){
hundredths = 0;
tenths = tenths +1;
if (tenths == 10){
tenths = 0;
secondsones = secondsones + 1;
if (secondsones == 10){
secondsones = 0;
secondstens = secondstens +1;
if (secondstens == 6){
secondstens = 0;
minutesones = minutesones + 1;
if (minutesones == 10){
minutesones = 0;
minutestens = minutestens +1;
if (minutestens == 6){
minutestens = 0;
hoursones = hoursons + 1;
if (hoursones == 10){
hoursones = 0;
hourstens = hourstens +1;
if ( (hourstens == 2) && (hoursones == 4){
hoursones = 0;
hourstens = 0;
} // 24 hr rollover check
} //hourstens rollover check
} // hoursones rollover check
} // minutestens rollover check
} // minutesones rollover check
} // secondstens rollover check
} // secondsones rollover check
} // tenths rollover check
} // hundredths rollover check
} // hundredths passing check
if (oldsecondsones != secondsones){ // show elapsed time
oldsecondsones = secondsones;
serial.print(hourstens);
serial.print(hoursones);
serial.print(":");
serial.print(minutestens);
serial.print(minutesones);
serial.print(":");
serial.print(secondstens);
serial.println(secondsones);
} // end 1 second check
// time perform action?
if ((hourstens == xx) && (hoursones == xx) && (minutestens == xx) && (minutesones == xx) ){
// time feed dog! set off alarm! open drapes! whatever!
}
} // end loop
Arduino Forum > Using Arduino > Project Guidance > Programming Arduino with 2.3 Motor Shield and millis function
arduino
Comments
Post a Comment