#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ordinary=2;
int hs=3;
int hsmod1=4;
int blc=5;
int outer=6;
int inner=7;
int snubber=8;
int newSpring=9;
int green=10;
int yellow=11;
int orange=12;
int white=13;
int red=A2;
int counti=0;
int countj=0;
int bogietypeValue=0;
int springtypeValue=0;
int bogieType[4]={ordinary,hs,hsmod1,blc} ;
int springType[3]={outer,inner,snubber};
int led[5]={green,yellow,orange,white,red};
int ledGroup[6]={0,3,6,9,12,15};
String ledColor[5]={"Green","Yellow","Orange","White","Red"};
int standardHeightOld[4][3]={
{260,262,294},
{260,243,293},
{253,225,304},
{260,240,288}
};
void setup() {
Serial.begin(9600);
pinMode(ordinary,INPUT_PULLUP);
pinMode(hs,INPUT_PULLUP);
pinMode(hsmod1,INPUT_PULLUP);
pinMode(blc,INPUT_PULLUP);
pinMode(outer,INPUT_PULLUP);
pinMode(inner,INPUT_PULLUP);
pinMode(snubber,INPUT_PULLUP);
pinMode(green,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(orange,OUTPUT);
pinMode(white,OUTPUT);
pinMode(red,OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
//lcd.print("syam");
}
void loop() {
// delay(5);
for(int i=0;i<=3;i++){
if(digitalRead(bogieType[i])==LOW){
counti++;
bogietypeValue=i;
}
}
for(int j=0;j<=2;j++){
if(digitalRead(springType[j])==LOW){
countj++;
springtypeValue=j;
}
}
if(counti==1 & countj==1){
float springHeight=(((map(analogRead(A0),0,1023,0,10000))/100)+204);
//lcd.clear();
// lcd.setCursor(2,0);
// lcd.print("Spring Height");
lcd.setCursor(5,0);
lcd.print(springHeight);
float groupHeight=((standardHeightOld[bogietypeValue][springtypeValue]+1)-springHeight);
for(int i=0;i<=4;i++){
if(groupHeight>ledGroup[i]&groupHeight<=ledGroup[i+1]){
digitalWrite(led[i],HIGH);
//lcd.setCursor(5,0);
//lcd.print(springHeight);
lcd.setCursor(5,1);
lcd.print(ledColor[i]);
//lcd.print(ledColor[i])
}
else if(groupHeight>15 | groupHeight<0){
digitalWrite(led[i],HIGH);
lcd.setCursor(5,1);
lcd.print("Condemn");
}
else{
digitalWrite(led[i],LOW);
}
}
}
else{
//lcd.clear();
lcd.setCursor(3,0);
lcd.print("press valid");
lcd.setCursor(4,1);
lcd.print("Command");
}
counti=0;
countj=0;
delay(200);
lcd.clear();
}