SHARE
TWEET

GPS Serwomechanizm - bez biblioteki serwa

mario6996 Feb 25th, 2020 (edited) 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h> //Dołączenie biblioteki LCD
  2. #include <TinyGPS++.h> //biblioteka odpowiedzialna za lokalizator GPS
  3. #include <SoftwareSerial.h>
  4.  
  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. // Pulses duration: 600 - 0deg; 1450 - 90deg; 2300 - 180deg;
  14.  
  15.  
  16. LiquidCrystal lcd (2,3,4,5,6,7); //Informacja o podlaczeniu nowego wyswietlacza
  17. SoftwareSerial serial_connection(11, 10); //RX=pin 10, TX=pin 11
  18. TinyGPSPlus gps;
  19.  
  20. void setup(){
  21.  
  22.   pinMode(8, INPUT_PULLUP);
  23.   pinMode(9, OUTPUT);
  24.  
  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.   lcd.setCursor(10,0);
  31.   lcd.print(gps.speed.kmph());
  32.   lcd.setCursor(10,1);
  33.   lcd.print("0");
  34.  
  35.   Serial.begin(9600);
  36.   serial_connection.begin(9600);//This opens up communications to the GPS - Dowiedzieć się dlaczego nie działa!
  37. }
  38.  
  39. void loop(){
  40. while(serial_connection.available())//While there are characters to come from the GPS
  41.   {
  42. gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time  
  43.   }
  44.  
  45.  
  46.  
  47.   if(gps.location.isUpdated())
  48.   {
  49.  
  50.  
  51.   if(gps.speed.kmph() == 0 ){ //GPS = 0km/h -> Serwomechanizm 0"
  52.  
  53.     digitalWrite(9, HIGH);
  54.     delayMicroseconds(600);
  55.     digitalWrite(9, LOW);
  56.     delay(20);
  57.  
  58.    
  59.   lcd.setCursor(10,0);
  60.   lcd.print(gps.speed.kmph());
  61.   lcd.setCursor(10,1);
  62.   lcd.print("0");
  63. }
  64.  
  65.  
  66.  
  67. if(gps.speed.kmph() <= 1 && gps.speed.kmph() > 0 ){ //GPS > 90km/h -> Serwomechanizm 20"
  68.  
  69.     digitalWrite(9, HIGH);
  70.     delayMicroseconds(700);
  71.     digitalWrite(9, LOW);
  72.     delay(20);
  73.  
  74.    
  75.   lcd.setCursor(10,0);
  76.   lcd.print(gps.speed.kmph());
  77.   lcd.setCursor(10,1);
  78.   lcd.print("10");
  79. }
  80.  
  81.  
  82.  
  83. if(gps.speed.kmph() > 1 && gps.speed.kmph() < 2 ){ //GPS > 90km/h -> Serwomechanizm 20"
  84.  
  85.     digitalWrite(9, HIGH);
  86.     delayMicroseconds(900);
  87.     digitalWrite(9, LOW);
  88.     delay(20);
  89.    
  90.  
  91.   lcd.setCursor(10,0);
  92.   lcd.print(gps.speed.kmph());
  93.   lcd.setCursor(10,1);
  94.   lcd.print("30");
  95. }
  96.  
  97.  
  98.  
  99. if(gps.speed.kmph() >= 2 && gps.speed.kmph() < 30){//GPS > 120km/h -> Serwomechanizm 50"
  100.  
  101.     digitalWrite(9, HIGH);
  102.     delayMicroseconds(1100);
  103.     digitalWrite(9, LOW);
  104.     delay(20);
  105.  
  106.   lcd.setCursor(10,0);
  107.   lcd.print(gps.speed.kmph());
  108.   lcd.setCursor(10,1);
  109.   lcd.print("50");
  110. }
  111.  
  112.  
  113.  
  114. if(gps.speed.kmph() > 30 && digitalRead(8) == LOW ){ //GPS > 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 80"
  115.  
  116.     digitalWrite(9, HIGH);
  117.     delayMicroseconds(1400);
  118.     digitalWrite(9, LOW);
  119.     delay(20);
  120.  
  121.   lcd.setCursor(10,0);
  122.   lcd.print(gps.speed.kmph());
  123.   lcd.setCursor(10,1);
  124.   lcd.print("80");
  125. }
  126.  
  127.  
  128.  
  129. if(gps.speed.kmph() < 1 && digitalRead(8) == LOW ){ //GPS < 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 0"
  130.  
  131.     digitalWrite(9, HIGH);
  132.     delayMicroseconds(600);
  133.     digitalWrite(9, LOW);
  134.     delay(20);
  135.  
  136.  
  137.   lcd.setCursor(10,0);
  138.   lcd.print(gps.speed.kmph());
  139.   lcd.setCursor(10,1);
  140.   lcd.print("0");
  141. }
  142.  
  143.  
  144. }}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top