I hope i have this in the right place.
So this is my 1st project. it works 99%, just 1 issue.
Board is a Nano clone.
It's intended to turn on pin 7 if either pin 10 or 11 are HIGH
and not turn on if pin 12 is HIGH
then wait for a timeout and do it again
no pin High is by design a fast loop where nothing happens.
Most of the code is for the LCD display which ok and works just as intended
The issue is the last "esle if"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Declare pins
int ledPin = 13; //Pin to trigger external LED
int triggerPin = 7; //Pin to trigger external device
int skipPin = 12; //Pin to read for high status to set skip
int run10Pin = 11;
int run15Pin = 10;
//Declare counts
int count = 0; //Initial event count
int skipCount = 0; //Count of skipped activations
//Declare LCD outputs
int countPos = 14; //Position of event counter
int countLine = 2; //Line for event count
int statusPos = 11; //Position of Status output
int statusLine = 1; //Line For status output
int skipPos = 10; //Position of Status output
int skipLine = 3; //Line For status output
//Declare general
int run10On = 600000; // 10 minutes
int run10Test = 20000; // shorter test
int run10Off = 85800000; //23hrs 50 Min
int test10Off = 30000;
int run15On = 900000; // 15 minutes
int run15Test = 20000; //shorter time for testing
int run15Off = 85500000; //23hrs 45 Min
int test15Off = 50000;
int skipTime = 864000000; // 24 hour skip time
int skipTest = 30000; // 1 min skip for testing
void setup() {
//start Serial Monitor
Serial.begin(9600);
// Controller setup, to run once:
pinMode(triggerPin, OUTPUT); //Set Pin to trigger output
pinMode(ledPin, OUTPUT); //Set Pin to trigger LED
pinMode(skipPin, INPUT); //Set pin to read for setting skip state
pinMode(run10Pin, INPUT); //Set pin to read for setting 10 min run
pinMode(run15Pin, INPUT); //Set pin to read for setting 15 min run
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn on backlight
lcd.print(" Magic Bucket"); // Print a message to the LCD
digitalWrite(triggerPin, LOW); //set device status to off
digitalWrite(ledPin, LOW); //set LED status to off
}
void loop() {
// main device code, to run repeatedly:
Serial.println("top of loop");
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print("Water is :");
lcd.setCursor(0, 2); // set the cursor to column 0, line 1
lcd.print("Activations :");
lcd.setCursor(0, 3); // set the cursor to column 0, line 1
lcd.print("Skipped : ");
if (digitalRead(skipPin) == HIGH) { //Check if Skip pin is set high
skipCount++; // Increment skipped counter
digitalWrite(triggerPin, LOW); //turn device off
digitalWrite(ledPin, LOW); //turn LED off
lcd.setCursor(statusPos, statusLine); // set the cursor to column 12, line 1
lcd.print("Skipped");
lcd.setCursor(skipPos, skipLine); // set the cursor to counter position.
lcd.print(skipCount); //print count of skipped activations
delay(skipTest); //SKIP Runtime
//delay(skipTime); //SKIP Runtime
Serial.println("end of skip");
} else if (digitalRead(run10Pin) == HIGH) {
digitalWrite(triggerPin, HIGH); //turn device on
digitalWrite(ledPin, HIGH); //turn device on
count++; // Increment counter
lcd.setCursor(statusPos, statusLine); // set the cursor to column 12, line 1
lcd.print("On - 10m ");
lcd.setCursor(countPos, countLine); // set the cursor to counter position.
lcd.print(count); //print count of activations
delay(run10Test); // 10 test runtime
//delay(run10On); //ON Runtime
//set off time
lcd.setCursor(statusPos, statusLine); // set the cursor to column 12, line 1
digitalWrite(triggerPin, LOW); //turn device off
digitalWrite(ledPin, LOW); //turn LED off
lcd.print("Off ");
delay(test10Off); //test10Off time
//delay(run10Off); //run10 time off
Serial.println("end of 10delay");
} else if (digitalRead(run15Pin) == HIGH) {
digitalWrite(triggerPin, HIGH); //turn device on
digitalWrite(ledPin, HIGH); //turn device on
count++; // Increment counter
lcd.setCursor(statusPos, statusLine); // set the cursor to column 12, line 1
lcd.print("On - 15m ");
lcd.setCursor(countPos, countLine); // set the cursor to counter position.
lcd.print(count); //print count of activations
delay(run15Test); // 15 test Runtime
//delay(run15On); //ON Runtime
//set off time
lcd.setCursor(statusPos, statusLine); // set the cursor to column 12, line 1
digitalWrite(triggerPin, LOW); //turn device off
digitalWrite(ledPin, LOW); //turn LED off
lcd.print("Off ");
Serial.println("start of 15delay");
delay(test15Off); //test10Off time
//delay(run15Off); //run10 time off
Serial.println("end of 15delay");
} else {
Serial.println("final else");
}
}
bool i2CAddrTest(uint8_t addr) {
Wire.begin();
Wire.beginTransmission(addr);
if (Wire.endTransmission() == 0) {
return true;
}
return false;
}
this is the serial output if pin 10 is high.
It activates, turns of and that's the last this it does, it never gets to the "end of 15delay" statement
23:02:12.646 -> top of loop
23:02:32.744 -> start of 15delay
This is the output from the other 2 activated modes. (Pin 12 and the Pin 11 HIGH) No issues at all
23:30:39.794 -> top of loop
23:31:09.887 -> end of skip
23:31:09.887 -> top of loop
23:31:39.957 -> end of skip
23:31:39.957 -> top of loop
23:32:29.998 -> end of 10delay
23:32:29.999 -> top of loop
23:33:20.123 -> end of 10delay
23:33:20.123 -> top of loop
23:34:10.168 -> end of 10delay
23:34:10.168 -> top of loop
I gather I'm missing something to do with the If/else framework, but I'd like to know why the 1st to sections work fine and the program runs continuously for days, but the run15 section literally runs once, then begins the delay and then everything stops
all times values are short testing values as this is intended to run once a day.
I'm sure somewhere in here "millis" should be used but i haven't got my head around this yet.
Any advice gratefully received.
Thank you