Advertisement
Guest User

Yeetus Arduinos

a guest
Dec 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #define trigPin 11 // Trigger Pin
  3. #define echoPin 12 // Echo Pin
  4. #define spekerPin 8
  5. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  6. int toneArr[8] = {523, 587, 657, 698, 784, 880, 987};
  7. long duration, distance;
  8. byte time;
  9. void setup()
  10. {
  11. Serial.begin (9600);
  12. lcd.begin(16, 2);
  13. pinMode(trigPin, OUTPUT);
  14. pinMode(echoPin, INPUT);
  15. digitalWrite(trigPin, LOW);
  16. }//End of setup function
  17.  
  18. void loop()
  19. {
  20. digitalWrite(trigPin, HIGH);
  21. delayMicroseconds(10);
  22. digitalWrite(trigPin, LOW);
  23. duration = pulseIn(echoPin, HIGH);
  24. Serial.print("Distance = ");
  25. lcd.setCursor(0, 0);
  26. lcd.print("Distance = CM");
  27. lcd.setCursor(10, 0);
  28. distance = duration / 58;
  29. Serial.println(distance);
  30. lcd.print(distance);
  31. if (distance < 60) {
  32. tone(spekerPin, toneArr[2]);
  33. delay(distance * 5);
  34. tone(spekerPin, toneArr[5]);
  35. delay(distance * 2);
  36. }
  37. else
  38. noTone(spekerPin);
  39. delay(50);
  40. lcd.clear();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement