SHARE
TWEET

Arduino - Miernik odległości, LCD i dioda

B3ar6 Mar 22nd, 2019 (edited) 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define rled 13
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  5. int Trig = 2;
  6. int Echo = 3;
  7. int CM;
  8. long CZAS;
  9. int n=0;
  10.  
  11. void setup()
  12. {
  13.   pinMode(rled, INPUT_PULLUP);
  14.   pinMode(Trig, OUTPUT);
  15.   pinMode(Echo, INPUT);
  16.   wyswietlacz();
  17. }
  18.  
  19. void loop()
  20. {
  21.   lcd.clear();
  22.   n++;
  23.   pomiar();
  24.   digitalWrite(rled, HIGH);
  25.   delay(100);
  26.   digitalWrite(rled, LOW);
  27.   lcd.print("proba: ");
  28.   lcd.print(n);
  29.   lcd.setCursor(0,1);
  30.   lcd.print("odleglosc: ");
  31.   lcd.print(CM);
  32.   lcd.print("cm");
  33.   delay(10000);
  34. }
  35.  
  36. void wyswietlacz()
  37. {
  38.   lcd.begin(16,2);
  39.   for(int i=0;i<3;i++)
  40.   {
  41.     lcd.backlight();
  42.     delay(100);
  43.     lcd.noBacklight();
  44.     delay(100);
  45.   }
  46.   lcd.backlight();
  47.   lcd.display();
  48.   lcd.setCursor(0,0);
  49. }
  50.  
  51. void pomiar()
  52. {
  53. digitalWrite(Trig, LOW);
  54. delayMicroseconds(2);
  55. digitalWrite(Trig, HIGH);
  56. delayMicroseconds(15);
  57. digitalWrite(Trig, LOW);
  58. digitalWrite(Echo, HIGH);
  59. CZAS = pulseIn(Echo, HIGH);
  60. CM = CZAS/58;
  61. }
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