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
- #define OUT 3
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Ustawienie adresu ukladu na 0x27
- int StanSensora = 0, OstatniStan=0;
- float DrugiSensor = 0, OstatniStanDrugiego=0;
- float numerdrugiego = 0, 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(0,1); //Ustawienie kursora w pozycji 0,0 (drugi wiersz, pierwsza kolumna)
- lcd.print("OUT:");
- delay(500);
- lcd.setCursor(6,0); //Ustawienie kursora w pozycji 10,0 (pierwszy wiersz, dziesiata kolumna)
- lcd.print("?: ");
- delay(500);
- lcd.setCursor(16,0);
- lcd.print("%");
- pinMode(SENSORPIN, INPUT);
- pinMode(OUT, INPUT);
- digitalWrite(SENSORPIN, HIGH);
- digitalWrite(OUT, HIGH);
- }
- 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);
- DrugiSensor = digitalRead(OUT);
- if (DrugiSensor && !OstatniStanDrugiego) {
- lcd.setCursor(4,1);
- lcd.print((int)round(numerdrugiego));
- delay(5);
- }
- if (!DrugiSensor && OstatniStanDrugiego) {
- numerdrugiego = numerdrugiego+1;
- lcd.setCursor(4,1);
- lcd.print((int)round(numerdrugiego));
- }
- OstatniStan = StanSensora;
- OstatniStanDrugiego = DrugiSensor;
- delay(5);
- lcd.setCursor(9,0);
- lcd.print((100-(numerdrugiego/numer)*100));
- delay(10);
- }
Add Comment
Please, Sign In to add comment