No spory bo ostatecznie i tak potrzebujesz pomiar a nie oporność
tu masz na deser działający kod
Kod:
//#include <ShiftRegLCD123.h>
//ShiftRegLCD123 lcd( 7, 6, SRLCD123);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlightpin, polarity
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
int rok ;
byte miesiac ;
byte dzien ;
byte godzina ;
byte minuta ;
byte sekunda ;
long pm ;
long zm ;
byte Lcd = 2;
int POM[10];
byte x = 0 ;
long Pm = 0 ;
byte Srednia = 0 ;
byte LPG = 0 ;
void setup () {
lcd.begin(16,2);
lcd.backlight();
lcd.clear();
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
rtc.adjust(DateTime(2016, 5, 6, 18, 15, 0));
}
}
void loop () {
long cm = millis();
if ( cm - zm > 10000 ){
if (Lcd != 2){Lcd = 2;lcd.clear();zm = cm;}
else if (Lcd != 1){Lcd = 1;lcd.clear();zm = cm;}
}
DateTime now = rtc.now();
rok = now.year(),DEC;
miesiac = now.month(),DEC;
dzien = now.day(),DEC;
godzina = now.hour(),DEC;
minuta = now.minute(),DEC;
sekunda = now.second(),DEC;
if ( cm - pm >= 500 ){
int pom = analogRead(A0)/4;
POM[x] = pom ;
x = x + 1 ;
pm = cm ;
}
if ( x > 9 ){
Srednia = (POM[0]+POM[1]+POM[2]+POM[3]+POM[4]+
POM[5]+POM[6]+POM[7]+POM[8]+POM[9])/10 ;
x = 0;}
LPG = map( Srednia,0,255,0,100 ); // podstaw za 2 pierwsze zmienne dla 0 min odczyt z czujnika
switch(Lcd){
case 1:
lcd.setCursor(3, 0);
lcd.print(zero(dzien));
lcd.print('/');
lcd.print(zero(miesiac));
lcd.print("/");
lcd.print(rok);
lcd.print(" ");
lcd.setCursor(4, 1);
lcd.print(zero(godzina));
lcd.print(":");
lcd.print(zero(minuta));
lcd.print(":");
lcd.print(zero(sekunda));
lcd.print(" ");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Poziom LPG");
lcd.setCursor(0, 1);
lcd.print("zbiornika");
lcd.setCursor(11, 1);
lcd.print(sto(LPG));
lcd.print('%');
break;
}
}
int zero(int number) {
if (number < 10){lcd.print('0');}
return number;}
int sto(int number) {
if (number < 100){lcd.print('0');}
if (number < 10){lcd.print('0');}
return number;}