// constants won't change. They're used here to set pin numbers:
const int buttonPin = 8; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
#include <LiquidCrystal.h>
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// Variables
int Count = 0; // Counter to keep track of the number of objects
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" Starting Up");
delay(2000);
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(150);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pump 1");
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
++Count; // Increment the object count when an object is detected
delay(15000); // Delay 15 seconds
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
lcd.setCursor(9, 0);
lcd.print(Count);
}
}