Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import lcd libary:
- #include <LiquidCrystal.h>
- //variabels for pins in arduino chip:
- int TrigPin = 9;
- int EchoPin = 10;
- //distance reading variabels:
- long Duratation;
- int Distance;
- int NewDistance;
- int Speed;
- int v1;
- int v2;
- unsigned long time;
- // initialize the library by associating any needed LCD interface pin
- // with the arduino pin number it is connected to
- const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 5000;
- void setup()
- {
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- //input signal and output signal to read distance:
- pinMode(TrigPin, OUTPUT);
- pinMode(EchoPin, INPUT);
- pinMode(12, INPUT);
- digitalWrite(12, HIGH);
- // ger bit värde och printar på displayn
- Serial.begin(9600);
- lcd.print("Distance: ");
- lcd.setCursor(0, 1);
- lcd.print("Speed: ");
- //9600 bit comunication from pc to arduino:
- //--------------------LCD_DISPLAY---------------------'
- }
- void loop()
- {
- //skickar ut signal genom sensorn och väntar 2 milli secunder.
- digitalWrite(TrigPin, LOW);
- delayMicroseconds(2);
- //skickar ut echo signal tillbaks genom sensorn och väntar 2 milli secunder.
- digitalWrite(TrigPin, HIGH);
- delayMicroseconds(5);
- //omvandlar "Duratation" variablen till värdet av signalen av sensorn man får in för att få ut avståndet
- Duratation = pulseIn(EchoPin, HIGH);
- //omvändlar avståndet till centimeter
- Distance = (Duratation / 2 * 0.034);
- //väntar 0.18 sekunder
- delay(180);
- //--------------------LCD_DISPLAY---------------------
- //print speed and distance on lcd display:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement