#include <NewPing.h>
#define trigPin 2
#define echoPin 3
#define max_distance 120
int LEDgreen = 5;
int LEDyellow = 6;
int LEDred = 7;
long distance;
NewPing sonar(trigPin, echoPin, max_distance);
void setup() {
//Serial.begin(9600);
//Serial.println("Parkassistant");
pinMode(LEDgreen, OUTPUT);
pinMode(LEDyellow, OUTPUT);
pinMode(LEDred, OUTPUT);
digitalWrite(LEDgreen, LOW);
digitalWrite(LEDyellow, LOW);
digitalWrite(LEDred, LOW);
}
void loop() {
delay(500);
distance = sonar.ping_cm();
//Serial.println(distance);
switch (distance) {
case 0:
digitalWrite(LEDgreen, LOW);
digitalWrite(LEDyellow, LOW);
digitalWrite(LEDred, LOW);
break;
case 31 ... 60:
digitalWrite(LEDgreen, LOW);
digitalWrite(LEDyellow, HIGH);
digitalWrite(LEDred, LOW);
break;
case 1 ... 30:
digitalWrite(LEDgreen, LOW);
digitalWrite(LEDyellow, LOW);
digitalWrite(LEDred, HIGH);
break;
default:
digitalWrite(LEDgreen, HIGH);
digitalWrite(LEDyellow, LOW);
digitalWrite(LEDred, LOW);
break;
}
}