Made some changes to the display so it tells me when the delays are on.
so it keeps looping in this part of the program when the switch is low
}
else {
Serial.println("1 OFF");
Serial.println(potValue1);
lcd.setCursor(3, 3);
lcd.print("OFF");
lcd.print(" ");
lcd.setCursor(16, 3);
lcd.print("OFF");
lcd.print(" ");
delay(potValue1);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
}
how can i stop this happing.
i only wont it to run this part if the switch gose from HIGH to LOW
But if the switch is on the programe keeps looping there aswell i only wont it to run it once then wait for a change in the switch.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,21);
int potPin = A6; // Potentiometer Pin
int potPin1 = A7; // Potentiometer Pin
int led1 = 5; // Green
int led2 = 6; // Green
int potValue = 0; // variable from the sensor
int potValue1 = 0;
const int buttonPin0 = A0;
int buttonState0 = 0;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(buttonPin0, INPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.begin(20, 4);
}
void loop(){
buttonState0 = digitalRead(buttonPin0);
potValue = analogRead(potPin);
potValue = map(potValue, 0, 1023, 1000, 60000);
potValue1 = analogRead(potPin1);
potValue1 = map(potValue1, 0, 1023, 1000, 60000);
lcd.setCursor(7, 0);
lcd.print("TIMER");
lcd.setCursor(0, 1);
lcd.print("ON DELAY:");
lcd.setCursor(10, 1);
lcd.print(potValue);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("OFF DELAY:");
lcd.setCursor(10, 2);
lcd.print(potValue1);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("SW:");
lcd.setCursor(10, 3);
lcd.print("DELAY:");
lcd.setCursor(16, 3);
lcd.print(" ");
delay(500);
if (buttonState0 == HIGH) {
Serial.println("1 ON"); //A0 = DIP 1
Serial.println(potValue);
lcd.setCursor(3, 3);
lcd.print("ON");
lcd.print(" ");
lcd.setCursor(16, 3);
lcd.print("ON");
lcd.print(" ");
delay(potValue);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
}
else {
Serial.println("1 OFF");
Serial.println(potValue1);
lcd.setCursor(3, 3);
lcd.print("OFF");
lcd.print(" ");
lcd.setCursor(16, 3);
lcd.print("OFF");
lcd.print(" ");
delay(potValue1);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
}