Close

Odpověď na: mega2560 web i2cLCD16x4 termostat vyvoj

Úvodní stránka Fórum Vaše projekty Arduino mega2560 web i2cLCD16x4 termostat vyvoj Odpověď na: mega2560 web i2cLCD16x4 termostat vyvoj

#4308
Profilový obrázekjurda23
Účastník

problem s web byl vyřešen nevšimnul jsem si že používám porty 10, 11, 12, 13 ktere potřebuje ethernet shild

[code]
#include <SD.h>
#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <MemoryFree.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>

float T00;
float T01;
float T02;
//float T03;
// zde si upravte podle sebe
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0xC4, 0x36 };
// IP adresa

byte ip[] = { 192, 168, 99, 150 };
byte gateway[] = { 192, 168, 99, 1 };
byte subnet[] = { 255, 255, 255, 0 };
String readString;
// port
EthernetServer server(80);
//RGBLED
int bluePin1 = 40; //Digital Pin fĂĽr Blaue LED1 in RGB-LED
int greenPin1 = 41; //Digital Pin fĂĽr GrĂĽne LED1 in RGB-LED
int redPin1 = 42; //Digital Pin fĂĽr Rote LED1 in RGB-LED

int redIn1 = 0;
int greenIn1 = 1;
int blueIn1 = 2;

int redVal1;
int greenVal1;
int blueVal1;

int bluePin2 = 4; //Digital Pin fĂĽr Blaue LED2 in RGB-LED
int greenPin2 = 5; //Digital Pin fĂĽr GrĂĽne LED2 in RGB-LED
int redPin2 = 6; //Digital Pin fĂĽr Rote LED2 in RGB-LED

int redIn2 = 3;
int greenIn2 = 4;
int blueIn2 = 5;

int redVal2;
int greenVal2;
int blueVal2;

//Relays
int relPin1 = 2; //Digital Pin fĂĽr Relay1
int relPin2 = 3; //Digital Pin fĂĽr Relay2
int relPin3 = 8; //Digital Pin fĂĽr Relay3
int relPin10 = 22; //Digital Pin fĂĽr Relay22
int relPin11 = 24; //Digital Pin fĂĽr Relay24

int relPin1In = 22;
int relPin2In = 1;
int relPin3In = 5;
int relPin10In = 23;
int relPin11In = 25;

int relPin1Val;
int relPin2Val;
int relPin3Val;
int relPin10Val;
int relPin11Val;
//Heater Status
int heiz1Val;
int heiz2Val;
//#define WS5200_CS 10
//#define SDCARD_CS 4
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 32
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//Adresy CIDEL
DeviceAddress C = { 0x28, 0xC0, 0x97, 0x8A, 0x06, 0x00, 0x00, 0x74 };
DeviceAddress Cc = { 0x28, 0x3E, 0x11, 0x8A, 0x06, 0x00, 0x00, 0x42 };
DeviceAddress Ccc = { 0x28, 0x73, 0x9B, 0x89, 0x06, 0x00, 0x00, 0x83 };
//DeviceAddress C03 = { 0x28, 0x73, 0x9B, 0x89, 0x06, 0x00, 0x00, 0x83 };
int backLight = 13; // pin 13 will control the backlight
int LEDbrightness; //

void setup() {
sensors.begin();
Serial.begin(9600);

Ethernet.begin(mac, ip, gateway, subnet);

server.begin();

sensors.requestTemperatures();
Serial.print(„server is at „);
Serial.println(Ethernet.localIP());

// Velikost slova (bit) 9 10 11 12
//Rozlišení (°C) 0.5 0.25 0.125 0.0625
//Doba převodu (ms) 93,75 187,5 375 750
sensors.setResolution(C, 9);
sensors.setResolution(Cc, 9);
sensors.setResolution(Ccc, 9);
//sensors.setResolution(C03, 9);
lcd.begin(16, 4);
lcd.clear(); // initialize the lcd
lcd.backlight();

//T03 = sensors.getTempC(C03); //teplota solaru
pinMode(relPin1, OUTPUT); //Output Mode for Relay1
pinMode(relPin2, OUTPUT); //Output Mode for Relay2
pinMode(relPin3, OUTPUT); //Output Mode for Relay3
pinMode(relPin10, OUTPUT); //Output Mode for Relay2
pinMode(relPin11, OUTPUT); //Output Mode for Relay3
// digitalWrite(relPin1, HIGH);
// digitalWrite(relPin2, HIGH);
// digitalWrite(relPin3, HIGH);
// digitalWrite(relPin10, HIGH);
// digitalWrite(relPin11, HIGH);

}

void loop() {

sensors.requestTemperatures();
T00 = sensors.getTempC(C); //teplota bazenu
T01 = sensors.getTempC(Cc); //teplota panelu
T02 = sensors.getTempC(Ccc); //teplota solaru
//T03 = sensors.getTempC(C03); //teplota solaru

lcd.setCursor(0, 0);
lcd.print(„Bazen: „);
lcd.print(T00); //teplota venku
lcd.print(„C“);
lcd.setCursor(0, 2);
lcd.print(„Ohrev: „);
lcd.print(T01); //teplota solaru
lcd.print(„C“);
// Serial.println();
// Serial.print(„T0 „);
// Serial.print(T00);
// Serial.println();
// Serial.print(„T1 „);
// Serial.print(T01);
// Serial.println();
// Serial.print(„T2 „);
// Serial.print(T02);

//Je nach Temperatur Farbe der RGB-LED anpassen und Rel 1 schalten
if(T01 <= 27)
{
redVal1 = 0;
greenVal1 = 0;
blueVal1 = 150;
relPin1Val = LOW;
relPin3Val = LOW;
lcd.setCursor(0, 1);
lcd.print(„Topeni: Zap „);
}
else if(T01 > 27 && T01 < 29)
{
redVal1 = 0;
greenVal1 = 150;
blueVal1 = 0;
relPin1Val = HIGH;
relPin3Val = LOW;
lcd.setCursor(0, 1);
lcd.print(„Topeni: Vyp „);
}
else if(T01 > 29)
{
redVal1 = 150;
greenVal1 = 0;
blueVal1 = 0;
relPin1Val = HIGH;
relPin3Val = HIGH;
lcd.setCursor(0, 1);
lcd.print(„VÄ›tránĂ­: Vyp „);
}

//Je nach Temperatur Farbe der RGB-LED anpassen und Rel 2 schalten
if(T02 <= 27)
{
redVal2 = 0;
greenVal2 = 0;
blueVal2 = 255;
relPin2Val = LOW;
lcd.setCursor(0, 3);
lcd.print(„Topeni: Zap „);
}
else if(T02 > 27 && T02 < 29)
{
redVal2 = 0;
greenVal2 = 255;
blueVal2 = 0;
relPin2Val = HIGH;
lcd.setCursor(0, 3);
lcd.print(„Topeni: Vyp „);
}
else if(T02 > 29)
{
redVal2 = 255;
greenVal2 = 0;
blueVal2 = 0;
relPin2Val = HIGH;
lcd.setCursor(0, 3);
lcd.print(„Topeni: Vyp „);
}
{

analogWrite(redPin1, redVal1);
analogWrite(greenPin1, greenVal1);
analogWrite(bluePin1, blueVal1);
analogWrite(redPin2, redVal2);
analogWrite(greenPin2, greenVal2);
analogWrite(bluePin2, blueVal2);
digitalWrite(relPin1, relPin1Val);
digitalWrite(relPin2, relPin2Val);
digitalWrite(relPin3, relPin3Val);
digitalWrite(relPin10, relPin10Val);
digitalWrite(relPin11, relPin11Val);

}

Serial.println();
Serial.print(„Locating devices…“);
Serial.print(„Found „);
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(“ devices.“);
//Serial.print(„Free Memory = „);
//Serial.println(getFreeMemory());
// když je připojen klient, zjistíme, zda jsou odeslána data
// od klienta směrem k nám
EthernetClient client = server.available();
String buffer = „“;

// dokud je klient připojen
while (client.connected()) {
// čti data od něj dokud nenarazíš na znak nového řádku

if (client.available()) {
char c = client.read();
buffer = buffer + c;
if (c == ‚\n‘) {

if(buffer.indexOf(„rele1=1“)>=0)
digitalWrite(2,HIGH);

else if(buffer.indexOf(„rele1=0“)>=0)
digitalWrite(2,LOW);

if (buffer.indexOf(„rele2=1“) >= 0)
digitalWrite(3, HIGH);
else if (buffer.indexOf(„rele2=0“) >= 0)
digitalWrite(3, LOW);

if (buffer.indexOf(„rele10=1“) >= 0)
digitalWrite(22, HIGH);

else if (buffer.indexOf(„rele10=0“) >= 0)
digitalWrite(22, LOW);

if (buffer.indexOf(„rele11=1“) >= 0)
digitalWrite(24, HIGH);

else if (buffer.indexOf(„rele11=0“) >= 0)
digitalWrite(24, LOW);

// delay(1);
// odešle klasickou hlavičku HTML stránky
client.println F ((„HTTP/1.1 200 OK“));
client.println F ((„Content-Type: text/html“));
client.println F ((„Connection: close“));

client.println ();
client.println F ((„<!DOCTYPE HTML>“));

// zde již klasická html data
client.println F ((„<html>“));
client.println F ((„<head>“));
// Název stránky
client.println F ((„<title>Arduinio Server – Rele control</title>“));
client.println F ((„</head>“));
client.println F ((„<body>“));
client.print F ((„<h3 align=center>Program pro ovladani rele</h3>“));
client.println F ((„</br>“));

// vygeneruje formulář

if (digitalRead(2)) {
client.print F ((„<button style=’background:red;width:20%;height:30px‘>RELE 1 VYPNUTO</button>“));
} else {
client.print F ((„<button style=’background:green;width:20%;height:30px‘>RELE 1</button>“));
}
client.println F ( (“        test“));
client.println F ((„</br>“));

if (digitalRead(3)) {
client.print F ((„<button style=’background:red;width:20%;height:30px‘>RELE 2 VYPNUTO</button>“));
} else {
client.print F ((„<button style=’background:green;width:20%;height:30px‘>RELE 2</button>“));
}
client.println F ((“        svetlo“));
client.println F ((„</br>“));

if (digitalRead(22)) {
client.print F ((„<button style=’background:red;width:20%;height:30px‘>RELE 3 VYPNUTO</button>“));
} else {
client.print F ((„<button style=’background:green;width:20%;height:30px‘>RELE 3</button>“));

client.println F ((“        filtrace“));
client.println F ((„</br>“));

if (digitalRead(24)) {
client.print F ((„<button style=’background:red;width:20%;height:30px‘>RELE 4 VYPNUTO</button>“));
} else {
client.print F ((„<button style=’background:green;width:20%;height:30px‘>RELE 4</button>“));
}
client.println F ((“        tlacitko pro kotel 4″));

client.println F ((„</br>“));
client.println F ((„</br>“));
client.println („</br>“);

client.println („Teplota0“);

client.println (T00);
client.println („</br>“);
client.println („Teplota1:“);

client.println (T01);
client.println („</br>“);
client.println („Teplota2:“);

client.println (T02);
client.println („</br>“);

client.print („<meta http-equiv=\“refresh\“ content=\“5\“>“); //stránka se naÄŤte automaticky jednou za 3 s
client.println („</body>“);
client.println („</html>“);

Serial.println(buffer);

delay(1); //dáme klientovi čas na zpracování
//ukončí přenos
client.stop();
} }
}
} }

[/code]