For more information visit:
http://www.ijcrt.org/viewfull.php?&p_id=IJCRT2110262
{ Vol 9- Issue 10- October 2021- Page no. c261-c272 }
//Display,setting,reset button , photoelectricsensor(Outputs 12Volt)
//Interrupt
//int pin = 2; //define interrupt pin to 2
int pin = 12; //define Count Reset4\00 pin to 2
int counter=0;
int currentState =0;
int previousState=0;
int prevCnt;
int a=1; //to avoid sensor repeatation
int b=1;//to avoid UP button repeatation
int c=1;//to avoid DOWN button repeatation
//****************//
//PB pins...
int s=0;
int setpin=8; //set button
int upin=9; //PB connected for incremnt
int dpin=10; //PB connected for decremnt
int rpin=11; //reset limit pin
int z=0; //for Set purpose
int x;
int led_pin=13;
//****************//
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 1);
LiquidCrystal lcd(5, 4,3, 2, 1, 0); //RS,E D4,D5,D6,D7
void setup() {
//****************//
pinMode(upin, INPUT_PULLUP);
pinMode(dpin, INPUT_PULLUP);
pinMode(setpin,INPUT_PULLUP);
pinMode(rpin,INPUT_PULLUP);
pinMode(led_pin,OUTPUT);
//****************//
pinMode(12,INPUT_PULLUP); /*RESET count ***********************************************************************/
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setCursor(0, 4);
lcd.print("Powered By");
delay(300);
lcd.clear();
lcd.setCursor(0, 4);
lcd.print("Shriram");
delay(300);
lcd.clear();
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("COUNT");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(counter);
//attachInterrupt(digitalPinToInterrupt(pin), blink,FALLING );
}
void loop() {
//+++++++++++++++++++++
//+++++++++++++++++++Start
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
//Serial.println(voltage);
if(voltage==5.00){
// digitalWrite(led_pin,HIGH);
if(a==1){
counter = counter + 1;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(counter);
a=2;
}
}
else{
a=1;
}
//+++++++++++++++++++
//++++++++++++++++++END
//*******************************
//*******************************
if(digitalRead(pin)==LOW){
RESET_COUNT();
}
if(digitalRead(setpin)==LOW){
// s=!s; //s will toggle between 0 and 1 only when set pressed.
// Serial.println("S:" );
// Serial.println(s);
lcd.setCursor(13, 0);
lcd.print("SET"); // . means Setting is running
up();
down();
res();
}
/*when set button is press and s==1
then only following statement will run*/
/*
if(s==1){
lcd.setCursor(13, 0);
lcd.print("SET"); // . means Setting is running
up();
down();
// s=0;
}
*/
else{
//This z is global variable hence we get updated z.
//Serial.println(z);
lcd.setCursor(13, 0);
lcd.print("-->"); //Setting isn't running
lcd.setCursor(13, 1);
lcd.print(z);
}
if(counter==z&&z!=0&&digitalRead(setpin)==HIGH){
// Serial.println("Same");
digitalWrite(led_pin,HIGH);
if(voltage!=5.00){
counter=0;
digitalWrite(led_pin,LOW);
lcd.setCursor(0, 1);
lcd.print(0);
}
}
else{
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
//lcd.setCursor(0, 1);
// print the number of seconds since reset:
//lcd.print(millis() / 1000);
/*
lcd.print(1);
delay(1000);
lcd.print(2);
lcd.print(5);
delay(1000);
lcd.print(6);
*/
}
void RESET_COUNT() {
//ISR function
// state = !state; //toggle the state when the interrupt occurs
counter=0;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("0 ");
//Serial.println(counter);
}
//When z==0 then counter will run for infinity.
int up(){
if(digitalRead(upin)==LOW) {
if(b==1){
//Serial.println("Shriram");
z=z+1;
// Serial.println(z);
lcd.setCursor(13, 1);
lcd.print(" ");
lcd.setCursor(13, 1);
lcd.print(z);
b=2; }//if(b==1) end
}// if(digitalRead(upin)==LOW) end
else{
b=1;
}
} //up() end
int down(){
if(digitalRead(dpin)==LOW&&z>0) {
if(c==1){
z=z-1;
if(z>=10){
lcd.setCursor(13, 1);
lcd.print(z);
}
else{
lcd.setCursor(13, 1);
lcd.print(" ");
lcd.setCursor(13, 1);
lcd.print(z); }
c=2;} //if(c==1) end
} // if(digitalRead(dpin)==LOW&&z>0) end
else{
c=1;
}
} //down() end
int res(){
if(digitalRead(rpin)==LOW) {
z=0;
lcd.setCursor(13, 1);
lcd.print("0 "); }
}
By:
<script src="https://platform.linkedin.com/badges/js/profile.js" async defer type="text/javascript"></script>
<div class="badge-base LI-profile-badge" data-locale="en_US" data-size="medium" data-theme="dark" data-type="VERTICAL" data-vanity="mehul-patil-711549219" data-version="v1"><a class="badge-base__link LI-simple-link" href="https://in.linkedin.com/in/mehul-patil-711549219?trk=profile-badge">Mehul Patil</a></div>
