Witaj Wojtku.
Tamten układ poprawiłem, oznaczenie rezystorów było złe, ale faktycznie miałem podpięty rezystor 4,7 kOma, z resztą zostały one podpięte pod pin 12 w trybie pasożytniczym. Powodem "skoków" temperatur był brak ustawionej rozdzielczości termometrów, po dodaniu:
Kod:
sensors.setResolution(P1, 12);
sensors.setResolution(P2, 12);
sensors.setResolution(P3, 12);
Wszystko działa tak jak należy, przekaźniki póki co odpuściłem, więc nie wiem czy problem z przygaszaniem wyświetlacza nadal istnieje.
Teraz próbuję to wszystko "ubrać" w obudowę. Ale chciałbym coś więcej
. Stąd dokupienie keypad'a 1x4.
Póki co znalazłem fajną bibliotekę "OneButton.h" która umożliwia odczytanie naciśnięcia, podwójnego naciśnięcia i przytrzymania klawiszy. Jako, że programista ze mnie taki jak z koziego zadka trąbka, stworzenie pod nią menu na lcd zajmie mi lata świetlne.
------------------
Nie poddaje się jednak, ale potrzebuje waszej pomocy.
Poprzez przytrzymanie jednego z klawiszy chce wywołać "ekran" z nastawami, konkretnie, przytrzymuje przycisk 1 włącza się ekran z opcjami:
- zmiana nastawu temperatury ( przycisk 2 temperatura w dół - przycisk 3 temperatura w górę i przycisk 4 zatwierdzam ).
- włączenie - wyłączenie przekaźników także przyciskami 2, 3 lub 4. Trzy będą zależnie od temperatury - nastawu ).
- jeden przekaźnik będzie działać jako włącznik czasowy i czas załączania i wyłączania też wypadało by regulować.
Kod do obsługi klawiszy mam oparty na bibliotece OneButton i wygląda tak:
Kod:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "OneButton.h"
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneButton button1(5, true);
OneButton button2(6, true);
OneButton button3(4, true);
OneButton button4(3, true);
// setup code here, to run once:
void setup() {
// Setup the Serial port. see http://arduino.cc/en/Serial/IfSerial
Serial.begin(9600);
lcd.begin(20,4);
// while (!Serial) {
//; // wait for serial port to connect. Needed for Leonardo only
// }
lcd.setCursor (0, 0);
lcd.print("Starting 4Buttons...");
// link the button 1 functions.
button1.attachDuringLongPress(longPress1);
// link the button 2 functions.
button2.attachClick(click2);
// link the button 3 functions.
button3.attachClick(click3);
// link the button 4 functions.
button4.attachClick(click4);
} // setup
// main code here, to run repeatedly:
void loop() {
// keep watching the push buttons:
button1.tick();
button2.tick();
button3.tick();
button4.tick();
// You can implement other code in here or just wait a while
delay(10);
} // loop
// ----- button 1 callback functions
void longPress1() {
lcd.clear();
lcd.setCursor (0, 0);
lcd.print("Button 1 longPress.");
}
// ... and the same for button 2:
void click2() {
lcd.setCursor (0, 1);
lcd.print("Button 2 click.");
} // click2
//3
void click3() {
lcd.setCursor (0, 2);
lcd.print("Button 3 click.");
}
//4
void click4() {
lcd.setCursor (0, 3);
lcd.print("Button 4 click.");
}
// End
To chyba wszystko co chciałbym na tą chwilę osiągnąć, poniżej kod który udało mi się posklejać i działa bez wyżej wymienionych funkcji.
Kod:
#include <DS1307RTC.h>
#include <Time.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
#define DS1307_ADDRESS 0x68
#define RELAY_ON 0 // 0 means active low relay
#define RELAY_OFF 1
#define Relay_1 11 // Arduino Digital I/O pin number
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
#define ONE_WIRE_BUS 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int nastaw = 26; // ustaw temperature
int przekaznik8 = 8; // pin przekaznik
int przekaznik9 = 9; // pin przekaznik
int przekaznik10 = 10; // pin przekaznik
byte state = LOW;
const char *monthName[12] = {
"Sty", "Lut", "Mar", "Kwi", "Maj", "Cze",
"Lip", "Sie", "Wrz", "Paź", "Lis", "Gru"
};
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 };
//DeviceAddress P4 = { 0x28, 0x00, 0x00, 0x1F, 0x07, 0x00, 0x00, 0x00 };
void setup()
{
Serial.begin(9600);
sensors.begin();
sensors.setResolution(P1, 12);
sensors.setResolution(P2, 12);
sensors.setResolution(P3, 12);
Wire.begin();
digitalWrite(Relay_1, RELAY_OFF);
pinMode(Relay_1, OUTPUT);
pinMode(przekaznik8, OUTPUT);
pinMode(przekaznik9, OUTPUT);
pinMode(przekaznik10, OUTPUT);
lcd.begin(20, 4);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop(){
printDate();
}
byte bcdToDec(byte val) {
return ( (val / 16 * 10) + (val % 16) );
}
void printDate() {
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
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
if ((hour == 11 ) && (minute == 00))
digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
if ((hour == 19) && (minute == 00))
digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
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) < (nastaw)) {
digitalWrite(8, HIGH);
int val = digitalRead(8);
if (val)
lcd.setCursor(9, 1);
lcd.print("Ok ");
} else {
lcd.setCursor(9, 1);
lcd.print("Wla");
digitalWrite(8, LOW);
}
lcd.setCursor (0, 2);
lcd.write(byte(0));
lcd.print(" ");
lcd.print(tempC2, 2);
lcd.write(byte(223));
if (sensors.getTempCByIndex(1) < (nastaw)) {
digitalWrite(9, HIGH);
int val = digitalRead(9);
if (val)
lcd.setCursor(9, 2);
lcd.print("Ok ");
} else {
lcd.setCursor(9, 2);
lcd.print("Wla");
digitalWrite(9, LOW);
}
lcd.setCursor (0, 3);
lcd.write(byte(0));
lcd.print(" ");
lcd.print(tempC3, 2);
lcd.write(byte(223));
if (sensors.getTempCByIndex(2) < (nastaw)) {
digitalWrite(10, HIGH);
int val = digitalRead(10);
if (val)
lcd.setCursor(9, 3);
lcd.print("Ok ");
} else {
lcd.setCursor(9, 3);
lcd.print("Wla");
digitalWrite(10, LOW);
}
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 LCDprint2digits(int number) {
if (number >= 0 && number < 10) {
lcd.write('0');
}
lcd.print(number);
}
Teraz moja prośba do Was, wskazówki jak się do tego zabrać, czy konieczne będzie przerwanie, a może trzeba zacząć od uporządkowania całego kodu bo jest tam bałagan, liczę na sugestie, tylko błagam, nie podnoście mi poprzeczki zbyt wysoko i tak dużo osiągnąłem jak na moją znajomość elektroniki.