I am new to Arduino and have been playing around with this case statement for my fish feeder. It has a hole in the lid and spins on a stepper motor and the proxy picks it up as it spins around, the first case it to avoid it stopping at 180 degrees then case 1 inches it towards the prox and case 2 then is the run on the make it straight again as it comes back around. As I work away for a week at a time if the proxy fails, I want it to default can anyone give me advice on how they think this code has been written. I am currently away so have not tested it yet, the default is there so at least it spins once per 12 hours.
// fish feeder without RTC with proxy
#include <Stepper.h>
#define STEPS 32 // motor steps
Stepper stepper(STEPS, 13, 10, 11, 12); // write pins high for stepper motor
#define prox 2
void setup() {
Serial.begin(9600);
pinMode(prox, INPUT_PULLUP); // pull up as NPN prox
stepper.setSpeed(200); // stepper speed MAX
}
void loop() {
int feedfish; // steps to feed fish
byte steps;
switch (steps) {
case 0:
feedfish = 1504;
stepper.step(feedfish); // feed fish
steps++;
break;
case 1:
feedfish = 32;
stepper.step(feedfish); // feed fish
if (prox == true) {
steps++;
}
break;
case 2:
feedfish = 0; // tune this run on amount at home
stepper.step(feedfish);
if (prox == true) // possibly not needed just checking prox again
{
digitalWrite(10, LOW); // write pins low due to holding current
digitalWrite(11, LOW); // write pins low due to holding current
digitalWrite(12, LOW); // write pins low due to holding current
digitalWrite(13, LOW); // write pins low due to holding current
delay(43200000); // delay 12 hours
steps = 0; // rewrite steps to 0
break;
} else {
steps++;
}
default:
feedfish = 2048;
stepper.step(feedfish);
digitalWrite(10, LOW); // write pins low due to holding current
digitalWrite(11, LOW); // write pins low due to holding current
digitalWrite(12, LOW); // write pins low due to holding current
digitalWrite(13, LOW); // write pins low due to holding current
delay(43200000); // delay 12 hours
}
}
Advice on code written.
Gunny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.