12-03-2017, 14:13
To jeszcze taka uwaga iż setup wykonuje się jeden raz podczas uruchamiania programu a loop w kółko .
Ocena wątku:
Kilka czujników temp. + termostat 2-przekaznikowy
|
(12-03-2017, 14:17)namok napisał(a): Nie działa tak jak oczekujesz bo nie rozumiesz różnicy pomiędzy finkcją setup() a loop(). Jest to wyjaśnione w każdym kursie arduino.
Formatowanie kodu dalej masz w głębokim poważaniu.
#include <LiquidCrystal_I2C.h>
#include <Wire.h> //
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS18B20.h>
#include "max6675.h"
//Definicje, definicje:
#define SO_PIN 2 // 6675 Serial Output
#define CS_PIN 3 // 6675 Chip Select
#define CK_PIN 4 // 6675 Clock Pin
#define TOO_HOT 75.0 // To try limit calculation
#define TOO_COLD 62.5
MAX6675 thermocouple(CK_PIN, CS_PIN, SO_PIN);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(7); //Podłączenie do 7
DallasTemperature sensors(&oneWire); //Przekazania informacji do biblioteki
float DegreesC;
DeviceAddress a = { 0x28, 0xFF, 0x6E, 0xE5, 0x33, 0x16, 0x4, 0x2E };
DeviceAddress b = { 0x28, 0xFF, 0x3, 0xE7, 0x33, 0x16, 0x4, 0xD4 };
void setup(void) {
sensors.requestTemperatures(); //Pobranie temperatury czujnika
Serial.print("Woda: ");
Serial.println(sensors.getTempCByIndex(0)); //Wyswietlenie informacji
Serial.print("Powietrze: ");
Serial.println(sensors.getTempCByIndex(1)); //Wyswietlenie informacji
Serial.print("Czopuch: ");
Serial.println(DegreesC);
DegreesC=(thermocouple.readCelsius());
sensors.begin();
lcd.begin(16,2);
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
}
void loop(void) {
lcd.setCursor(0,0);
lcd.print("W=");
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(0,1);
lcd.print("P=");
lcd.print(sensors.getTempCByIndex(1));
lcd.setCursor(8,1);
lcd.print("C=");
lcd.print(DegreesC);
}
(12-03-2017, 14:53)Minek3 napisał(a): Dzięki namok (szkoda że nie napisałeś że pomyliłem te dwie funkcje) ważne że działa wyświetlenie wszystkich 3 czujnikówOdpowiedzi udzielił wcześniej @-adamek:
(12-03-2017, 14:13)-adamek napisał(a): To jeszcze taka uwaga iż setup wykonuje się jeden raz podczas uruchamiania programu a loop w kółko .Mój post miał Ci uzmysłowić że mało wiesz i powinieneś zacząć od podstaw. Jeśli obrażasz się na konstruktywną krytykę to nie powinieneś pisać na forach bo są ludzie bardziej wredni niż ja.
#include <LiquidCrystal_I2C.h>
#include <Wire.h> //
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS18B20.h>
#include "max6675.h"
//Definicje, definicje:
#define SO_PIN 2 // 6675 Serial Output
#define CS_PIN 3 // 6675 Chip Select
#define CK_PIN 4 // 6675 Clock Pin
#define TOO_HOT 75.0 // To try limit calculation
#define TOO_COLD 62.5
MAX6675 thermocouple(CK_PIN, CS_PIN, SO_PIN);
int p1 = 8;
int p2 = 6;
int p1state = 0;
int p2state = 0;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define ONE_WIRE_BUS 7
DeviceAddress a = { 0x28, 0xFF, 0x6E, 0xE5, 0x33, 0x16, 0x4, 0x2E };
DeviceAddress b = { 0x28, 0xFF, 0x3, 0xE7, 0x33, 0x16, 0x4, 0xD4 };
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float DegreesC;
int nastaw = 30; // ustaw temperature
int przekaznik = 11; // pin przekaznik
int przekaznik1 = 12; // pin przekaznik
void setup(void)
{
pinMode(przekaznik,OUTPUT);
lcd.begin(16, 2);
sensors.begin();
Serial.begin(9600);
}
void wys(void){
lcd.setCursor(0,0);
lcd.print("W=");
lcd.print(sensors.getTempCByIndex(1));
lcd.print(" ");
lcd.print("Z=");
lcd.print(nastaw);
lcd.setCursor(0,1);
lcd.print("P=");
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(8,1);
lcd.print("S=");
lcd.print(DegreesC);
if (sensors.getTempCByIndex(1) < (nastaw)) {
digitalWrite(11,HIGH);
} else {
digitalWrite(11,LOW);
}
}
void loop(void)
{
sensors.requestTemperatures(); //Pobranie temperatury czujnika
Serial.print("Woda: ");
Serial.println(sensors.getTempCByIndex(0)); //Wyswietlenie informacji
delay(500);
Serial.print("Powietrze: ");
Serial.println(sensors.getTempCByIndex(1)); //Wyswietlenie informacji
delay(500);
DegreesC = thermocouple.readCelsius();
Serial.print("C = ");
Serial.println(DegreesC);
delay(500);
p1state = digitalRead(p1);
p2state = digitalRead(p2);
if(p1state == HIGH){nastaw=nastaw+1;}
if(p2state == HIGH){nastaw=nastaw-1;}
wys();
}
(12-03-2017, 18:31)Minek3 napisał(a): Jedynie nie chce mi zaliczyć przekaźnika na pinie 12 tak aby załńczał się o 10*C no trudno i tak dużo zrobiłemW programie który wkleiłeś nie wykorzystujesz tego pinu poza definicją "int przekaznik1 = 12;"
#include <LiquidCrystal_I2C.h>
#include <Wire.h> //
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS18B20.h>
#include "max6675.h"
//Definicje, definicje:
#define SO_PIN 2 // 6675 Serial Output
#define CS_PIN 3 // 6675 Chip Select
#define CK_PIN 4 // 6675 Clock Pin
#define TOO_HOT 75.0 // To try limit calculation
#define TOO_COLD 62.5
MAX6675 thermocouple(CK_PIN, CS_PIN, SO_PIN);
int p1 = 8;
int p2 = 6;
int p1state = 0;
int p2state = 0;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define ONE_WIRE_BUS 7
DeviceAddress a = { 0x28, 0xFF, 0x6E, 0xE5, 0x33, 0x16, 0x4, 0x2E };
DeviceAddress b = { 0x28, 0xFF, 0x3, 0xE7, 0x33, 0x16, 0x4, 0xD4 };
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float DegreesC;
int nastaw = 30; // ustaw temperature
int nastaw1 = 45; // ustaw temperature
int przekaznik = 11; // pin przekaznik
int przekaznik1 = 12; // pin przekaznik
void setup(void)
{
pinMode (przekaznik,OUTPUT);
pinMode (przekaznik1,OUTPUT);
lcd.begin(16, 2);
sensors.begin();
Serial.begin(9600);
}
void wys(void){
lcd.setCursor(0,0);
lcd.print("W=");
lcd.print(sensors.getTempCByIndex(1));
lcd.print(" ");
lcd.print("Z=");
lcd.print(nastaw);
lcd.setCursor(0,1);
lcd.print("P=");
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(8,1);
lcd.print("S=");
lcd.print(DegreesC);
if (sensors.getTempCByIndex(1) < (nastaw)) {
digitalWrite(11,HIGH);
} else {
digitalWrite(11,LOW);
if (sensors.getTempCByIndex(1) < (nastaw1)) {
digitalWrite(12,HIGH);
} else {
digitalWrite(12,LOW);
}
}
}
void loop(void)
{
sensors.requestTemperatures(); //Pobranie temperatury czujnika
Serial.print("Woda: ");
Serial.println(sensors.getTempCByIndex(0)); //Wyswietlenie informacji
delay(500);
Serial.print("Powietrze: ");
Serial.println(sensors.getTempCByIndex(1)); //Wyswietlenie informacji
delay(500);
DegreesC = thermocouple.readCelsius();
Serial.print("C = ");
Serial.println(DegreesC);
delay(500);
p1state = digitalRead(p1);
p2state = digitalRead(p2);
if(p1state == HIGH){nastaw=nastaw+1;}
if(p2state == HIGH){nastaw=nastaw-1;}
wys();
}