Hi, I received a lot of help from CrossRoads (Thank you Sir!) but I am still having trouble. Could someone please correct this code for me or point me in the right direction. I am trying to learn how to communicate with the Ping Sensor and using a LED for feedback. I thought that this would make a good starting point. Thank you.
int LED = 13;
const int pingPin = 7;
int alarm = 0;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop()
{
if (pingPin < 10){
digitalWrite(LED, HIGH);}
else{
digitalWrite(LED, LOW);
}
float ping();
long duration, inches;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = (duration);
}
Ok, so I removed that portion however "7" declares the pin location for my Ping Sensor so I don't really understand why I can't use const since I will keep the sensor plugged into pin 7.
Could you tell me what's wrong with the below code
The compiler should be able to tell you. I'm posting from a tablet, so no compiler.
However, you were told way back that you can't expect a digitalRead to return anything other than zero or one.
I posted nearly complete code; why didn't you use it?