Advertisement
Sztuka_To_Tajfun

Kod ##1

Aug 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <Wire.h>   // standardowa biblioteka Arduino
  2. #include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD
  3. #include <Math.h>
  4. #define SENSORPIN 4
  5.  
  6. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Ustawienie adresu ukladu na 0x27
  7. int StanSensora = 0, OstatniStan=0;
  8. float numer = 0;
  9.  
  10.  
  11. void setup() {
  12.   lcd.begin(16,2);   // Inicjalizacja LCD 2x16
  13.  
  14.  
  15.   lcd.backlight(); // zalaczenie podwietlenia
  16.   delay(1000);
  17.   lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
  18.   lcd.print("IN:");
  19.   delay(500);
  20.   lcd.setCursor(10,0); //Ustawienie kursora w pozycji 10,0 (pierwszy wiersz, dziesiata kolumna)
  21.   lcd.print("?: "); // Wydajnosc w ilosci na h
  22.   delay(500);
  23.   pinMode(SENSORPIN, INPUT); // ustawienie pinu czujnika jako WEJSCIE
  24.   digitalWrite(SENSORPIN, HIGH); // stan wysoki czujnika
  25.  
  26.  
  27. }
  28.  
  29. void loop() {
  30.  delay(5);
  31.   lcd.setCursor(0,1);
  32.  StanSensora = digitalRead(4);
  33.   if (StanSensora && !OstatniStan) {
  34.     lcd.setCursor(3,0);
  35.     lcd.print((int)round(numer));
  36.     delay(1);
  37.    
  38.   }
  39.   if (!StanSensora && OstatniStan) {
  40.     numer = numer +1;
  41.     lcd.setCursor(3,0);
  42.     lcd.print((int)round(numer));
  43.   }
  44.   delay(5);
  45.  
  46.   OstatniStan = StanSensora;
  47.   delay(5);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement