I have made a object counter i.e if all sensors become high it increments in the counter ..in this way there is increment whenever all sensors becomes high...and objects are counted.Following is my code it works,
#include <LiquidCrystal.h>
int ledPin = 10; // choose the pin for the LED
//int a =2;
//int
//int // choose the input pin (for a pushbutton)
int a = 0; // variable for reading the pin status
int b=0;
int c=0;
int d=0;
int counter = 0;
int currentState = 0;
int previousState = 0;
LiquidCrystal lcd(13, 12, 11, 5, 6, 7, 8);
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(2, INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(9,INPUT);// declare pushbutton as input
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" STOCK COUNT ");
Serial.begin(9600);
//Serial.begin(9600);
}
void loop(){
a = digitalRead(2);
b = digitalRead(3);
c = digitalRead(4);
d = digitalRead(9);
if (a == HIGH && b==HIGH && c==HIGH && d==HIGH) {
digitalWrite(ledPin, HIGH); // turn LED on
currentState = 1;}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
lcd.setCursor(7, 1);
// print the number of seconds since reset:
lcd.print(counter);
Serial.print("stock count = " );
Serial.print(counter);
//Serial.println(counter);
}
}
previousState = currentState;
delay(250);
}
My query is i want to design such a system when object passes from left to right through FOUR SENSORS counter is incremented...and if object passes from right to left counter is decremented.
What modification in programming should i implement??