Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int trigPin = 38;
- const int echoPin = 39;
- const int detection = 160;
- const int rgreenb = 31;
- const int redgb = 30;
- const int rgblue = 33;
- long duration;
- int distance;
- int reserved;
- int inuse;
- void setup() {
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration * 0.034 / 2;
- if (distance <= detection) {
- rgb(0, 255, 255);
- inuse = 1;
- }
- if (distance > detection) {
- rgb(255, 0, 255);
- inuse = 0;
- }
- if (reserved == 1 && distance > detection) {
- rgb(255, 255, 0);
- }
- Serial.println(distance);
- delay(250);
- }
- void rgb(int r, int g, int b)//finkcia na zjednodusenie pouzivania rgb led zaradeny
- {
- #ifdef pre
- red = 255 - r;
- green = 255 - g;
- blue = 255 - b;
- #endif
- analogWrite(redgb, r);
- analogWrite(rgreenb, g);
- analogWrite(rgblue, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement