Advertisement
mario6996

GPS Serwomechanizm - problem z serwem

Feb 24th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <Servo.h> //biblioteka odpowiedzialna za serwo
  2. #include <LiquidCrystal.h> //Dołączenie biblioteki LCD
  3. #include <TinyGPS++.h> //biblioteka odpowiedzialna za lokalizator GPS
  4. #include <SoftwareSerial.h>
  5.  
  6. /*
  7. Spis pinów:
  8. 2,3,4,5,6,7 - LCD
  9. 8 - przycisk
  10. 9 - Serwomechanizm
  11. 10, 11 - RX, TX
  12. */
  13. LiquidCrystal lcd (2,3,4,5,6,7); //Informacja o podlaczeniu nowego wyswietlacza
  14. SoftwareSerial serial_connection(11, 10); //RX=pin 10, TX=pin 11
  15. TinyGPSPlus gps;
  16.  
  17. Servo serwomechanizm;
  18. int odczytanaWartosc = 0;
  19. int pozycjaSerwa = 120;
  20.  
  21.  
  22. void setup(){
  23. serwomechanizm.attach(9); //serwomechanizm pod 9
  24. pinMode(8, INPUT_PULLUP);
  25. lcd.begin(16,2);
  26. lcd.setCursor(0,0);
  27. lcd.print("Predkosc");
  28. lcd.setCursor(0,1);
  29. lcd.print("Kat. wych");
  30.  
  31. Serial.begin(9600);
  32. serial_connection.begin(9600);//This opens up communications to the GPS
  33.  
  34. }
  35.  
  36. void loop(){
  37.  
  38. serwomechanizm.write(pozycjaSerwa);
  39. lcd.setCursor(10,0);
  40. lcd.print(gps.speed.mph());
  41. lcd.setCursor(10,1);
  42. lcd.print(pozycjaSerwa);
  43.  
  44.  
  45. while(serial_connection.available())//While there are characters to come from the GPS
  46. {
  47. gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
  48. }
  49. if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  50. {
  51.  
  52. odczytanaWartosc = gps.speed.mph();
  53.  
  54. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55.  
  56. if(odczytanaWartosc > 1){ //GPS > 90km/h -> Serwomechanizm 20"
  57.  
  58.  
  59.  
  60. lcd.setCursor(10,0);
  61. lcd.print(gps.speed.mph());
  62. lcd.setCursor(10,1);
  63. lcd.print(pozycjaSerwa);
  64.  
  65. }
  66. if(odczytanaWartosc > 2){//GPS > 120km/h -> Serwomechanizm 50"
  67.  
  68.  
  69.  
  70. lcd.setCursor(10,0);
  71. lcd.print(gps.speed.mph());
  72. lcd.setCursor(10,1);
  73. lcd.print(pozycjaSerwa);
  74.  
  75. }
  76.  
  77. if(odczytanaWartosc > 30 && digitalRead(7) == LOW ){ //GPS > 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 80"
  78.  
  79.  
  80. lcd.setCursor(10,0);
  81. lcd.print(gps.speed.mph());
  82. lcd.setCursor(10,1);
  83. lcd.print(pozycjaSerwa);
  84.  
  85. }
  86.  
  87. if(odczytanaWartosc < 1 /*&& digitalRead(7) == LOW */){ //GPS < 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 0"
  88.  
  89.  
  90. lcd.setCursor(10,0);
  91. lcd.print(gps.speed.mph());
  92. lcd.setCursor(10,1);
  93. lcd.print(pozycjaSerwa);
  94.  
  95. }
  96.  
  97.  
  98. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement