I'm doing a project where I have to find time enters one end of a rug the other end (2 rugs are) but this is not the values ??of the time as it should appear on the LCD.
Anyone can discover the error in the program?
ps: I can not change the pins that are attached sensors
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int lcd_key = 0;
int adc_key_in = 0;
int sensor1 = 2;
int sensor2 = A5;
int sensor3 = 3;
int sensor4 = 13;
unsigned long time1 = 0;
unsigned long time2 = 0;
unsigned long time3 = 0;
unsigned long time4 = 0;
void setup()
{
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
pinMode(sensor3, INPUT);
pinMode(sensor4, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print ("* Queda Graves *");
lcd.setCursor(0,1);
lcd.print (" V1.0 2014 ");
delay (1500);
}
void loop ()
{
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Tb1 ms");
lcd.setCursor (0,1);
lcd.print ("Tb2 ms");
if (digitalRead(sensor1) == HIGH) {
time1 = millis ();
if (analogRead(sensor2) == HIGH) {
time2 = millis();
lcd.setCursor (5, 0);
delay(100);
lcd.print (time1 - time2);
Serial.println(time1 - time2);
}
}
else if (digitalRead(sensor3) == HIGH) {
time3 = millis();
if (digitalRead(sensor4) == HIGH) {
time4 = millis();
lcd.setCursor (5, 1);
delay(100);
lcd.print (time3 - time4);
Serial.println(time3 - time4);
}
}
}