12-02-2016, 17:22
Już nieistotne i przepraszam za kłopot, ale postanowiłem, że zostanie to w pierwotnej wersji, bo łatwiej mi operować w ten sposób na funkcji termometry. Problem miałem z histereza, bo przypisując do niej jedną zmienną globalną załączało mi trzy przekaźniki jednocześnie gdy jeden z czujników osiągnął pożądaną temperaturę i wyłączało wszystkie trzy gdy np. na drugim temperatura spadła poniżej dolnej pożądanej granicy. Rozwiązałem to w taki sposób, że do każdego czujnika przypisałem osobną zmienną.
Poniżej cały kod jakby ktoś chciał kiedyś skorzystać.
Teraz będę próbował wykorzystać Twój tuturial z majsterkowo - gotowiec3 - obsługa 3 przycisków, do zmiany parametru nastawu temperatury. Nie wiem czy mi coś z tego wyjdzie, zobaczymy, wszystkie wskazówki mile widziane.
Pozdrawiam
Poniżej cały kod jakby ktoś chciał kiedyś skorzystać.
Kod:
#include <DS1307RTC.h>
#include <Time.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DS1307_ADDRESS 0x68
#define LIGHT_ON 0
#define LIGHT_OFF 1
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define ONE_WIRE_BUS 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int nastaw = 26; // nastaw temperatury zalaczenia przekaznikow wentylatorow
int swiatlo = 11; // pin przekaznika oswietlenia
int went_1 = 8; // pin przekaznika wentylatora 1
int went_2 = 9; // pin przekaznika wentylatora 2
int went_3 = 10; // pin przekaznika wentylatora 3
volatile int his_1=0;
volatile int his_2=0;
volatile int his_3=0;
byte state = LOW;
const char *monthName[12] = {
"Sty", "Lut", "Mar", "Kwi", "Maj", "Cze",
"Lip", "Sie", "Wrz", "Paź", "Lis", "Gru"
};
byte temp[8] = //ikona temperatury
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
DeviceAddress P1 = { 0x28, 0xFF, 0xB2, 0x4C, 0x65, 0x14, 0x1, 0x6F };
DeviceAddress P2 = { 0x28, 0xFF, 0xE, 0x97, 0x65, 0x14, 0x1, 0x94 };
DeviceAddress P3 = { 0x28, 0xFF, 0x6E, 0x35, 0x65, 0x14, 0x1, 0x2B };
void setup()
{
Serial.begin(9600);
sensors.begin();
sensors.setResolution(P1, 12);
sensors.setResolution(P2, 12);
sensors.setResolution(P3, 12);
Wire.begin();
digitalWrite(swiatlo, LIGHT_OFF);
pinMode(swiatlo, OUTPUT);
pinMode(went_1, OUTPUT);
pinMode(went_2, OUTPUT);
pinMode(went_3, OUTPUT);
lcd.begin(20, 4);
lcd.createChar(0, temp);
}
void loop() {
czasidata();
czasowy();
termometry();
}
byte bcdToDec(byte val) {
return ( (val / 16 * 10) + (val % 16) );
}
void czasowy() {
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
if ((hour == 12 ) && (minute == 30))
digitalWrite(swiatlo, LIGHT_ON);
if ((hour == 12) && (minute == 31))
digitalWrite(swiatlo, LIGHT_OFF);
}
void czasidata() {
tmElements_t tm;
if (RTC.read(tm)) {
lcd.setCursor (0, 0);
LCDprint2digits(tm.Hour);
lcd.print(':');
LCDprint2digits(tm.Minute);
lcd.print(':');
LCDprint2digits(tm.Second);
lcd.setCursor (9, 0);
lcd.print(tm.Day);
lcd.print('/');
lcd.print(monthName[tm.Month-1]);
lcd.print('/');
lcd.print(tmYearToCalendar(tm.Year));
} else {
if (RTC.chipPresent()) {
lcd.println("DS1307 stoi. Uruchom Zegar");
}
else {
lcd.println("DS1307 blad oczczytu!");
lcd.println("sprawdz polaczenie");
}
}
}
void termometry() {
sensors.requestTemperatures();
float tempC1 = sensors.getTempC(P1);
float tempC2 = sensors.getTempC(P2);
float tempC3 = sensors.getTempC(P3);
lcd.setCursor (0, 1);
lcd.write(byte(0));
lcd.print(" ");
lcd.print(tempC1, 2);
lcd.write(byte(223));
if (sensors.getTempCByIndex(0)+his_1 < (nastaw)) {
his_1=0;
digitalWrite(went_1, HIGH);
int val = digitalRead(went_1);
if (val)
lcd.setCursor(9, 1);
lcd.print("Ok ");
} else {
his_1=2;
digitalWrite(went_1, LOW);
lcd.setCursor(9, 1);
lcd.print("Wla");
}
lcd.setCursor (0, 2);
lcd.write(byte(0));
lcd.print(" ");
lcd.print(tempC2, 2);
lcd.write(byte(223));
if (sensors.getTempCByIndex(1)+his_2 < (nastaw)) {
his_2=0;
digitalWrite(went_2, HIGH);
int val = digitalRead(went_2);
if (val)
lcd.setCursor(9, 2);
lcd.print("Ok ");
} else {
his_2=2;
digitalWrite(went_2, LOW);
lcd.setCursor(9, 2);
lcd.print("Wla");
}
lcd.setCursor (0, 3);
lcd.write(byte(0));
lcd.print(" ");
lcd.print(tempC3, 2);
lcd.write(byte(223));
if (sensors.getTempCByIndex(2)+his_3 < (nastaw)) {
his_3=0;
digitalWrite(went_3, HIGH);
int val = digitalRead(went_3);
if (val)
lcd.setCursor(9, 3);
lcd.print("Ok ");
} else {
his_3=2;
digitalWrite(went_3, LOW);
lcd.setCursor(9, 3);
lcd.print("Wla");
}
}
void LCDprint2digits(int number) {
if (number >= 0 && number < 10) {
lcd.write('0');
}
lcd.print(number);
}
Teraz będę próbował wykorzystać Twój tuturial z majsterkowo - gotowiec3 - obsługa 3 przycisków, do zmiany parametru nastawu temperatury. Nie wiem czy mi coś z tego wyjdzie, zobaczymy, wszystkie wskazówki mile widziane.
Pozdrawiam