int echoPin = 10; //pin 10 for the echo
int trigPin = 11; //pin 9 for trigger
int buzzPin = 12; //pin 12 for the buzzer
int ledRed = 6; //pin 6 for red LED
int ledGreen = 4; //pin 4 for green LED
int duration, inches, cm; // establish variables for duration of the ping, and the distance result
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(buzzPin, OUTPUT);
Serial.begin(9600); //sets up serial monitor
}
void loop() {
delay(100);
Serial.print("Ping: ");
Serial.println("cm");
//warning
{
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);
digitalWrite(buzzPin, HIGH);
}
//no warning
{
digitalWrite(ledGreen, HIGH);
digitalWrite(ledRed, LOW);
digitalWrite(buzzPin, LOW);
}
tone(buzzPin, 6);
}