Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h> //biblioteka odpowiedzialna za serwo
- #include <LiquidCrystal.h> //Dołączenie biblioteki LCD
- #include <TinyGPS++.h> //biblioteka odpowiedzialna za lokalizator GPS
- #include <SoftwareSerial.h>
- /*
- Spis pinów:
- 2,3,4,5,6,7 - LCD
- 8 - przycisk
- 9 - Serwomechanizm
- 10, 11 - RX, TX
- */
- LiquidCrystal lcd (2,3,4,5,6,7); //Informacja o podlaczeniu nowego wyswietlacza
- SoftwareSerial serial_connection(11, 10); //RX=pin 10, TX=pin 11
- TinyGPSPlus gps;
- Servo serwomechanizm;
- int odczytanaWartosc = 0;
- int pozycjaSerwa = 120;
- void setup(){
- serwomechanizm.attach(9); //serwomechanizm pod 9
- pinMode(8, INPUT_PULLUP);
- lcd.begin(16,2);
- lcd.setCursor(0,0);
- lcd.print("Predkosc");
- lcd.setCursor(0,1);
- lcd.print("Kat. wych");
- Serial.begin(9600);
- serial_connection.begin(9600);//This opens up communications to the GPS
- }
- void loop(){
- serwomechanizm.write(pozycjaSerwa);
- lcd.setCursor(10,0);
- lcd.print(gps.speed.mph());
- lcd.setCursor(10,1);
- lcd.print(pozycjaSerwa);
- while(serial_connection.available())//While there are characters to come from the GPS
- {
- gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
- }
- 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
- {
- odczytanaWartosc = gps.speed.mph();
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if(odczytanaWartosc > 1){ //GPS > 90km/h -> Serwomechanizm 20"
- lcd.setCursor(10,0);
- lcd.print(gps.speed.mph());
- lcd.setCursor(10,1);
- lcd.print(pozycjaSerwa);
- }
- if(odczytanaWartosc > 2){//GPS > 120km/h -> Serwomechanizm 50"
- lcd.setCursor(10,0);
- lcd.print(gps.speed.mph());
- lcd.setCursor(10,1);
- lcd.print(pozycjaSerwa);
- }
- if(odczytanaWartosc > 30 && digitalRead(7) == LOW ){ //GPS > 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 80"
- lcd.setCursor(10,0);
- lcd.print(gps.speed.mph());
- lcd.setCursor(10,1);
- lcd.print(pozycjaSerwa);
- }
- if(odczytanaWartosc < 1 /*&& digitalRead(7) == LOW */){ //GPS < 30km/h & Wciśniecie buttona(hamulec) -> Serwomechanizm 0"
- lcd.setCursor(10,0);
- lcd.print(gps.speed.mph());
- lcd.setCursor(10,1);
- lcd.print(pozycjaSerwa);
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement