Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h> // standardowa biblioteka Arduino
- #include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD
- #include <Math.h>
- #define SENSORPIN 4
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Ustawienie adresu ukladu na 0x27
- int StanSensora = 0, OstatniStan=0;
- float numer = 0;
- void setup() {
- lcd.begin(16,2); // Inicjalizacja LCD 2x16
- lcd.backlight(); // zalaczenie podwietlenia
- delay(1000);
- lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
- lcd.print("IN:");
- delay(500);
- lcd.setCursor(10,0); //Ustawienie kursora w pozycji 10,0 (pierwszy wiersz, dziesiata kolumna)
- lcd.print("?: "); // Wydajnosc w ilosci na h
- delay(500);
- pinMode(SENSORPIN, INPUT); // ustawienie pinu czujnika jako WEJSCIE
- digitalWrite(SENSORPIN, HIGH); // stan wysoki czujnika
- }
- void loop() {
- delay(5);
- lcd.setCursor(0,1);
- StanSensora = digitalRead(4);
- if (StanSensora && !OstatniStan) {
- lcd.setCursor(3,0);
- lcd.print((int)round(numer));
- delay(1);
- }
- if (!StanSensora && OstatniStan) {
- numer = numer +1;
- lcd.setCursor(3,0);
- lcd.print((int)round(numer));
- }
- delay(5);
- OstatniStan = StanSensora;
- delay(5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement