SHARE
TWEET

Untitled

a guest Jan 24th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //import lcd libary:
  2. #include <LiquidCrystal.h>
  3. //variabels for pins in arduino chip:
  4. int TrigPin = 9;
  5. int EchoPin = 10;
  6.  
  7. //distance reading variabels:
  8. long Duratation;
  9. int Distance;
  10. int NewDistance;
  11. int Speed;
  12. int v1;
  13. int v2;
  14. unsigned long time;
  15.  
  16. // initialize the library by associating any needed LCD interface pin
  17. // with the arduino pin number it is connected to
  18. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  19. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  20. unsigned long startMillis;
  21. unsigned long currentMillis;
  22. const unsigned long period = 5000;
  23.  
  24. void setup()
  25. {
  26.   // set up the LCD's number of columns and rows:
  27.   lcd.begin(16, 2);
  28.  
  29.   //input signal and output signal to read distance:
  30.   pinMode(TrigPin, OUTPUT);
  31.   pinMode(EchoPin, INPUT);
  32.   pinMode(12, INPUT);
  33.   digitalWrite(12, HIGH);
  34.   // ger bit värde och printar på displayn
  35.   Serial.begin(9600);
  36.   lcd.print("Distance: ");
  37.   lcd.setCursor(0, 1);
  38.   lcd.print("Speed: ");
  39.  
  40.   //9600 bit comunication from pc to arduino:
  41.  
  42.   //--------------------LCD_DISPLAY---------------------'
  43. }
  44.  
  45. void loop()
  46. {
  47.   //skickar ut signal genom sensorn och väntar 2 milli secunder.
  48.   digitalWrite(TrigPin, LOW);
  49.   delayMicroseconds(2);
  50.  
  51.   //skickar ut echo signal tillbaks genom sensorn och väntar 2 milli secunder.
  52.   digitalWrite(TrigPin, HIGH);
  53.   delayMicroseconds(5);
  54.  
  55.   //omvandlar "Duratation" variablen till värdet av signalen av sensorn man får in för att få ut avståndet
  56.   Duratation = pulseIn(EchoPin, HIGH);
  57.   //omvändlar avståndet till centimeter
  58.   Distance = (Duratation / 2 * 0.034);
  59.   //väntar 0.18 sekunder
  60.   delay(180);
  61.  
  62.  
  63.   //--------------------LCD_DISPLAY---------------------
  64.   //print speed and distance on lcd display:
  65.  
  66.  
  67. }
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