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;
}
}
}
//
//