Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <NewPing.h>
  2. #include <IRremote.h>
  3.  
  4. int wartosc = 0x0;
  5.  
  6. IRsend irsend;
  7.  
  8. #define trig 12
  9. #define echo 11
  10. #define max_dyst 30
  11. #define r 6
  12. #define y 5
  13. #define g 4
  14.  
  15. NewPing sonar(trig,echo,max_dyst);
  16.  
  17. void setup() {
  18. Serial.begin(115200);
  19. pinMode(trig,OUTPUT);
  20. pinMode(echo,INPUT);
  21. }
  22.  
  23. void loop() {
  24. int odleglosc = sonar.convert_cm(sonar.ping_median());
  25.  
  26. if (odleglosc<10 && odleglosc!=0) {
  27. digitalWrite(g,LOW);
  28. digitalWrite(y,LOW);
  29. digitalWrite(r,HIGH);
  30. Serial.println("wstecz");
  31. irsend.sendRC5(0x61, 12);
  32. wartosc = 0x61;
  33. delay(5000); //In this example, the signal will be repeated every 5 seconds, approximately.
  34. }
  35. else if (odleglosc>20) {
  36. digitalWrite(g,HIGH);
  37. digitalWrite(y,LOW);
  38. digitalWrite(r,LOW);
  39. Serial.println("do przodu");
  40. irsend.sendRC5(0x60, 12);
  41. wartosc = 0x60;
  42. delay(5000);
  43. }
  44. else if (odleglosc>=10 && odleglosc<=20){
  45. digitalWrite(g,LOW);
  46. digitalWrite(y,HIGH);
  47. digitalWrite(r,LOW);
  48. Serial.println("nic");
  49. wartosc = 0x0;
  50. delay(100);
  51. }
  52. else {
  53. Serial.println("stara wartosc");
  54. Serial.println(wartosc);
  55. irsend.sendRC5(wartosc,12);
  56. delay(2000);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement