We are designing a speed o meter using lasers and Ldrs.. there is some thing wrong with the code Pls help
Here is the code
#include <LiquidCrystal.h>
// these constants won't change:
// led connected to digital pin 13
const int knockSensor1 = A0; // the piezo is connected to analog pin 0
const int knockSensor2 = A1; //the piezo is connected to analog pin 1
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
int time1,time2,time3,time4,timeA,timeB;
int timed;
float velocity;
// these variables will change:
int sensorReading1 = 0;
int sensorReading2 = 0;// variable to store the value read from the sensor pin
// variable used to store the last LED status, to toggle the light
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(knockSensor1,INPUT);
pinMode(knockSensor2,INPUT);
// declare the ledPin as as OUTPUT
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
// use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading1 = analogRead(knockSensor1);
sensorReading2 = analogRead(knockSensor2);
// if the sensor reading is greater than the threshold:
while(1)
{
if (sensorReading1 >= threshold)
{
// toggle the status of the ledPin:
// update the LED pin itself:
// send the string "Knock!" back to the computer, followed by newline
time1=millis();
}
else if(sensorReading1<threshold)
{
time2=millis()-time1;
if(time2>=200)
timeA=time2;
}
if(sensorReading2>=threshold)
{
time3=millis();
}
else if(sensorReading2<threshold)
{
time4=millis()-time3;
if(time4>=200)
timeB=time4;
}
if (timeA>200 || timeB>200)
break;
}
timed=(timeA+timeB)/2000;
velocity=(0.02/timed)*(18/5);
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(velocity);
}