Hello,
I neen your help with my code.Where is the mistake? I made a video: - YouTube and here is my code:
#include<LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#include <EEPROM.h>
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
int Backlight =10;
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
/////////////////////////////////////////////
int btnSelect = 15;
int btnDown = 16;
int btnUp = 17;
////////////////////////////////////////////
boolean btnSound = true;
byte set1 = 30;
byte set2 = 30;
byte set3 = 30;
byte set4 = 70;
byte Menu = 0;
int pump1 = 11;
int heater = 12;
int pump2 = 12;
int Buzzer = 2;
////////////////////////////////////////////
byte buttonState1 = 0;
byte lastButtonState1 = 0;
byte buttonState2 = 0;
byte lastButtonState2 = 0;
byte buttonState3 = 0;
byte lastButtonState3 = 0;
void setup()
{
lcd.begin(16, 2);
// Show Intro
Intro();
///////////////////////////////////////////
pinMode(btnSelect, INPUT);
pinMode(btnDown, INPUT);
pinMode(btnUp, INPUT);
pinMode(pump1, OUTPUT);
pinMode(heater, OUTPUT);
pinMode(pump2, OUTPUT);
pinMode(Buzzer, OUTPUT);
}
//////////////////////////////////////////
void loop ()
{
BSelect();
BUp();
BDown();
UpdateLCD();
ReadTemperature();
}
//////////////////////////////////////////
void ReadTemperature()
{
sensors.setResolution(TEMPERATURE_PRECISION);
sensors.requestTemperatures();
float temperature1 = sensors.getTempCByIndex(0);
lcd.setCursor(0,0);
lcd.print("Katilas ");
lcd.print(sensors.getTempCByIndex(0));
lcd.print((char)223);
lcd.print("C");
float temperature2 = sensors.getTempCByIndex(1);
lcd.setCursor(0, 2);
lcd.print("Boileris ");
lcd.print(sensors.getTempCByIndex(1));
lcd.print((char)223);
lcd.print("C");
}
void UpdateLCD()
{
if (Menu == 1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Katilo siurblys");
lcd.setCursor(0,1);
lcd.print("< >");
lcd.setCursor(6,1);
lcd.print(set1);
lcd.print((char)223);
lcd.print("C");
}
else if (Menu == 2)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Boilerio temperatura");
lcd.setCursor(0,1);
lcd.print("< >");
lcd.setCursor(6,1);
lcd.print(set2);
lcd.print((char)223);
lcd.print("C");
}
else if (Menu == 3)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Boilerio siurblys");
lcd.setCursor(0,1);
lcd.print("< >");
lcd.setCursor(6,1);
lcd.print(set3);
lcd.print((char)223);
lcd.print("C");
}
else if (Menu == 4)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Aliarmas");
lcd.setCursor(0,1);
lcd.print("< >");
lcd.setCursor(6,1);
lcd.print(set4);
lcd.print((char)223);
lcd.print("C");
}
else if (Menu == 5)
{
WLCD(" Saugoti ", " <Saugoti?>");
}
}
char WLCD(char line[], char line2[])
{
lcd.clear();
lcd.setCursor(0,0);
lcd.write(line);
lcd.setCursor(0,1);
lcd.write(line2);
}
/////////////////////////////////////////////
void Intro()
{
lcd.clear();
delay(50);
lcd.setCursor(0,0);
lcd.print("Termostatas v1.0");
lcd.setCursor(1,1);
lcd.print("by Kornelijus");
delay(2000);
// Load Settings
set1 = EEPROM.read(0);
set2 = EEPROM.read(1);
set3 = EEPROM.read(2);
set4 = EEPROM.read(3);
}
/////////////////////////////////////////////
void clickSound()
{
digitalWrite(Buzzer, HIGH);
delay(30);
digitalWrite(Buzzer, LOW);
}
/////////////////////////////////////////////
void SaveAll()
{
byte savedN = 0;
if (set1 != EEPROM.read(0))
{
EEPROM.write(0, set1);
savedN++;
}
if (set2 != EEPROM.read(1))
{
EEPROM.write(1, set2);
savedN++;
}
if (set3 != EEPROM.read(2))
{
EEPROM.write(2, set3);
savedN++;
}
if (set4 != EEPROM.read(3))
{
EEPROM.write(3, set4);
savedN++;
}
if (savedN > 0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.write("6.Save Done:");
lcd.setCursor(0,1);
lcd.print(savedN);
lcd.write(" B Saved.");
delay(2000);
}
if (savedN == 0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.write("Nothing Changed");
lcd.setCursor(0,1);
lcd.write("Not Saving.");
delay(2000);
}
}
/////////////////////////////////////////////
void BSelect()
{
buttonState1 = digitalRead(btnSelect);
// compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) {
// if the state has changed, increment the counter
if (buttonState1 == HIGH)
{
// Btn Sound
if (btnSound == true)
{
clickSound();
}
Menu++;
if (Menu > 5)
Menu = 0;
}
lastButtonState1 = buttonState1;
UpdateLCD();
}
}
/////////////////////////////////////////////
void BDown()
{
buttonState2 = digitalRead(btnDown);
// compare the buttonState to its previous state
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH)
{
// Btn Sound
if (btnSound == true)
{
clickSound();
}
if (Menu == 1)
{
if (set1 < 30)
set1 = 30;
if (set1 > 30)
set1--;
}
if (Menu == 2)
{
if (set2 < 30)
set2 = 30;
if (set2 > 30)
set2--;
}
// Save?
if (Menu == 5)
{
SaveAll();
}
if (Menu == 3)
{
if (set3 < 30)
set3 = 30;
if (set3 > 30)
set3--;
}
if (Menu == 4)
{
if (set4 < 70)
set4 = 70;
if (set4 > 70)
set4--;
}
}
lastButtonState2 = buttonState2;
UpdateLCD();
}
}
//////////////////////////////////////////////////
void BUp()
{
buttonState3 = digitalRead(btnUp);
// compare the buttonState to its previous state
if (buttonState3 != lastButtonState3) {
// if the state has changed, increment the counter
if (buttonState3 == HIGH)
{
if (Menu == 1)
{
if (set1 < 120)
set1++;
if (set1 >= 120)
set1 = 30;
}
// Btn Sound
if (btnSound == true)
{
clickSound();
}
// Save Settings?
if (Menu == 5)
{
SaveAll();
}
if (Menu == 2)
{
if (set2 < 120)
set2++;
if (set2 >= 120)
set2 = 30;
}
if (Menu == 3)
{
if (set3 < 120)
set3++;
if (set3 >= 120)
set3 = 30;
}
if (Menu == 4)
{
if (set4 < 120)
set4++;
if (set4 >= 120)
set4 = 70;
}
}
lastButtonState3 = buttonState3;
UpdateLCD();
}
}