complex Arduino programs. Re-write your list of actions as states.
You will see delay() used a lot in Arduino examples. It's simple and it gets the basic point of the example working but it doesn't show you how to write more advanced programs.
Have you heard of a "state machine"? That concept will get you on your way to making very complex Arduino programs. Re-write your list of actions as states.
Your code looks like this after using the </> code tag.
byte sensorOne = 2;
byte sensorTwo = 3;
byte feedOne = 8;
byte feedTwo = 9;
byte augerOne = 16;
unsigned long feedEmptyMillis; // when feed level dropped below sensor
unsigned long turnOnDelay = 3000; // wait to turn on auger
unsigned long turnOffDelay = 10000; // turn off auger after this time
void setup() {
// put your setup code here, to run once:
pinMode (sensorOne, INPUT);
pinMode (sensorTwo, INPUT);
pinMode (feedOne, OUTPUT);
pinMode (feedTwo, OUTPUT);
pinMode (augerOne, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
Step by step
Solved in 2 steps