Odpověď na: Lacny termostat
Úvodní stránka › Fórum › Vaše projekty › Arduino › Lacny termostat › Odpověď na: Lacny termostat
20.7.2015 v 12:37
#3834
Účastník
#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
//#include <stdint.h>
#include "TouchScreen.h"
#define LCD_CS A3 //
#define LCD_CD A2 //
#define LCD_WR A1 //
#define LCD_RD A0 //
#define LCD_RESET A4 //
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin
// definice max a min tlaku na TouchScreen
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TS_MINX 131
#define TS_MINY 947
#define TS_MAXX 901
#define TS_MAXY 129
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); // inicializace TouchScreen
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // inicializace LCD
double cislo=1;
int x, y = 0;
TSPoint p;
int NASTAVENAteplota;
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS SCL
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device address
DeviceAddress insideThermometer;
void setup(void)
{
NASTAVENAteplota= EEPROM.read(0);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // 0=off
tft.reset();
tft.begin(0x9341); // inicializace naseho LCD shieldu
tft.fillScreen(WHITE);
sensors.begin();
if (!sensors.getAddress(insideThermometer, 0)) //tft.println("Unable to find address for Device 0");
delay(2);
sensors.setResolution(insideThermometer, 9);
tft.fillScreen(WHITE);
}
float temp=0;
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC!=temp)
{
temp=tempC;
tft.fillScreen(WHITE);
tft.print(temp);
}
}
void loop(void)
{
//digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
//digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
if((75<p.x)&&(p.x<220)&&(57<p.y)&&(p.y<170))
{
int menu=3;
tft.fillScreen(RED);
delay(500);
tft.fillScreen(WHITE);
////////////////////////////////////////////////////////
tft.setRotation(1);
tft.drawFastHLine(0,39,320,RED);
tft.drawFastHLine(0,40,320,RED);
tft.drawFastHLine(0,41,320,GREEN);
tft.drawFastHLine(0,42,320,GREEN);
tft.drawFastHLine(0,43,320,BLUE);
tft.drawFastHLine(0,44,320,BLUE);
tft.setTextColor(RED);
tft.setCursor(200,12);
tft.setTextSize(2);
tft.setRotation(1);
tft.print("KikoSonic");
tft.setCursor(5,5);
tft.setTextSize(4);
tft.setRotation(1);
tft.print("Menu");
tft.setCursor(62,168);
tft.setTextColor(BLACK);
tft.setTextSize(5);
tft.setRotation(1);
tft.print("-");
tft.drawRoundRect(40,150,70,70,10,BLACK); //spodny lavy
tft.setCursor(184,174);
tft.setTextColor(BLACK);
tft.setTextSize(4);
tft.setRotation(1);
tft.print("End");
tft.drawRoundRect(150,150,140,70,10,BLACK); //spodny pravy
tft.setCursor(62,78);
tft.setTextColor(BLACK);
tft.setTextSize(5);
tft.setRotation(1);
tft.print("+");
tft.drawRoundRect(40,60,70,70,10,BLACK); // vrch.lavy
tft.setCursor(184,90);
tft.setTextColor(BLACK);
tft.setTextSize(4);
tft.setRotation(1);
tft.print(NASTAVENAteplota);
while (menu==3){
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
if((140<p.x)&&(p.x<231)&&(30<p.y)&&(p.y<83)) //+
{
tft.setCursor(184,90);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.setRotation(1);
tft.print(NASTAVENAteplota);
NASTAVENAteplota++;
if (NASTAVENAteplota==100)
{
NASTAVENAteplota=99;
}
tft.setCursor(184,90);
tft.setTextColor(BLACK);
tft.setTextSize(4);
tft.setRotation(1);
tft.print(NASTAVENAteplota);
delay(200);
}
if((15<p.x)&&(p.x<105)&&(30<p.y)&&(p.y<83)) //-
{
tft.setCursor(184,90);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.setRotation(1);
tft.print(NASTAVENAteplota);
NASTAVENAteplota--;
if (NASTAVENAteplota==0)
{
NASTAVENAteplota=1;
}
tft.setCursor(184,90);
tft.setTextColor(BLACK);
tft.setTextSize(4);
tft.setRotation(1);
tft.print(NASTAVENAteplota);
delay(200);
}
if((15<p.x)&&(p.x<105)&&(111<p.y)&&(p.y<217)) //end
{
menu=0;
EEPROM.write(0, NASTAVENAteplota );
}
}
}
}
temp=0;
tft.fillScreen(RED);
delay(1000);
tft.fillScreen(WHITE);
}
//---------------------------menu----------------------
tft.setCursor(45, 80);
tft.setTextColor(BLACK);
tft.setTextSize(7);
tft.setRotation(1);
sensors.requestTemperatures(); // Send the command to get temperatures
if (temp>=NASTAVENAteplota)
//digitalWrite(13, LOW); //0=on
digitalWrite(13, HIGH);//opacna logika
//else
// digitalWrite(13, HIGH); // 1=off
if (temp<NASTAVENAteplota-0.5)
digitalWrite(13, LOW);//opacna logikaopacna logika
printTemperature(insideThermometer);
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
tft.print(deviceAddress[i], HEX);
}
}