const int trigPin = 7;
const int echoPin = 8;
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop()
{
long duration, inches, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(1000);
if (cm > 52)
{
digitalWrite (4,HIGH);
}
else if (cm < 46)
{
digitalWrite(4,LOW);
}
}
long microsecondsToInches(long microseconds)
{return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{return microseconds / 29 / 2;}
This is the code i am using in which i have to feed the centimeter limits in the if statement from the code itself .
but i want to put the centimeter limit by using a matrix keyboard.
Kindly help me with the modified code