Display of counter data on LCD

Hello everyone!
I have connected my arduino to a 555 timer IC. The clock pulses are given as input to my Arduino. Also I have 2 switches made on a breadboard. Now what i want is that my arduino should read the clock rom the 555 IC and whenever I make the switch ON, I want my counter to increase the value and show it on the LCD. I am giving my code. Please tell me if anything is wrong or if you have better code please help me.

thanks!

#include<Arduino.h>
#include<LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int xclock = 2; //Clock for X Axis

int xdirection = 0; //Direction for X axis //A2

float buttonPresses=0;

void setup()
{
Serial.begin(9600);

pinMode(xclock , INPUT); //2
digitalWrite(xclock, HIGH); //2

pinMode(xdirection, INPUT); //A4
digitalWrite(xdirection, HIGH); //A4
digitalWrite(xdirection, LOW); //A4

lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(“Digitech”);
delay(1500);
lcd.clear( );

}
void loop()
{

while(1)
{

/***************************************************/
if(digitalRead(xdirection)==HIGH) //Put A4 (RM9) high
{

if(digitalRead(xclock)==LOW) //Put 2(RM12) low //This is to check edge both if statements
{

if(digitalRead(xclock)==HIGH) //Put 3(RM12) high
{
buttonPresses++;
Serial.println ("Button press X count = ");
//buttonPresses++;
float rank=(buttonPresses/200);
//1 pulse is divided by 200 to get 5 micron.
Serial.println(rank, 2); //why //?
lcd.setCursor(1,0 );
lcd.print(“X”);

lcd.setCursor(6, 0);
lcd.print(rank);
lcd.setCursor(14, 0);
lcd.print(“mm”);
//digitalRead(xclock) ==LOW;

}
}
}

/***************************************************/
if(digitalRead(xdirection)==LOW ) //Direction of X axis
{

if(digitalRead(xclock)==LOW)
//X axix clock pin
{

if(digitalRead(xclock)==HIGH)
{
buttonPresses–;
Serial.println ("Button press X count = ");
float rank=(buttonPresses/200);
//Serial.println(rank, 3);
lcd.setCursor(1,0);
lcd.print(“X”);
Serial.println(rank, 2);
lcd.setCursor(6,0);
lcd.print(rank);
lcd.setCursor(14,0);
lcd.print(“mm”);
//digitalRead(xclock) ==LOW;
}
}
}

//
/
/

What is wrong is that you didn't use code tags. Please read the forum guide in the sticky post and then modify your post above and correct it.

ameyab1:
Please tell me if anything is wrong

Your {'s and }'s don't match- seems you're 2x} short

ameyab1:
if you have better code please help me.

I don't understand what it is you're trying to do, but does the code actually do what you want? You didn't say. (But with those 2x{'s missing it won't compile anyway.)

I'm sure the while(1) thing is unnecessary; why not let loop() do its job and let it, um, loop.

You are missing two closing braces at the end of you program.

Your while( 1 ) statement will keep you from returning to the Arduino control of the loop which will save you some time that you need to save. It's about the only thing that makes sense in this program.

You cannot test "direction" with a single wire.

Your test for xclock HIGH/LOW, LOW/HIGH is highly dependent upon the frequency and will only approximately work for a small timing window.

You will miss many cycles due to the Serial and LCD writes, but that might be OK for your application.

What frequency come those pulses at?

Do you want to use the internal pull-up resistor on this input or not? You turn it on and then immediately back off.

  pinMode(xdirection, INPUT);          //A4
    digitalWrite(xdirection, HIGH);      //A4
    digitalWrite(xdirection, LOW);       //A4

IF you want the internal pull-up, it can be written as a single command:

  pinMode(xdirection,INPUT_PULLUP);

You sequence of IF statements may product unexpected results, the internal "code to execute" will only be executed if the clock transitions from LOW to HIGH in the time between the IF statements.

if (digitalRead(xclock) == LOW) 
      {
        if (digitalRead(xclock) == HIGH) 
        { 
          //code to execute//
        }
      }

I don't think the OP is coming back...