Skocz do zawartości

Menu wyświetlacza dla pomiaru temperatury


Bonkers

Pomocna odpowiedź

Najbardziej oczywisty sposób to:

if (zmienna == 0) {

zmienna = 1;

} else {

zmienna = 0;

}

ale można też na przykład:

zmienna = (zmienna + 1) % 2;

W każdym razie zamieńmy teraz wszystkie "liczba" na tablicę, żeby mieć wartości dla min i dla max:

float liczba[2] = {0, 0};

i teraz tam, gdzie miałeś "liczba" użyjesz "liczba[zmienna]".

Tak przy okazji, nie lepiej by było użyć jakichś bardziej opisowych nazw zmiennych?

Link do komentarza
Share on other sites

Tak to ma być? (zmieniłem "zmienna" na "prog")

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

#define UP 4
#define DOWN 5
#define ENTER 6
float liczba[2] = {0,0};
int prog = 0;
bool flaga = true;
//Adres wyswietlacza
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

long last_up = 0; 
long last_down = 0;
long last_enter = 0;

void setup() {

Serial.begin(9600);

 pinMode( UP, INPUT_PULLUP);
 pinMode(DOWN, INPUT_PULLUP);
 pinMode(ENTER, INPUT_PULLUP);

 lcd.begin(16, 2);
 lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.setCursor(0, 0); //ustawienie kursora
 lcd.print("Liczba: ");

}

void loop() {

 if((digitalRead(ENTER)==LOW) && (millis() - last_enter > 200))
 {
   if(prog == 0)
   {
     prog = 1;

   }
   else
   {
     prog = 0;

   }
     last_enter = millis();
 }


 if(prog == 1){
   lcd.setCursor(0,0);
 lcd.print("MAX");
 }
 if(prog ==0){
 lcd.setCursor(0,0);
 lcd.print("MIN");
 }

 if(flaga!=false){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);

 flaga=false;
 }

 if((digitalRead(UP)==LOW) && (millis() - last_up > 200))
 {

   liczba[prog]+=0.1;
   last_up = millis();

   flaga = true;

 }
 if((digitalRead(DOWN)==LOW) && (millis() - last_down > 200))
 { 

   liczba[prog]-=0.1;
   last_down = millis();
   flaga = true;
 }



}
Link do komentarza
Share on other sites

Aha jeszcze muszę ustawić, żeby przy zmianie na MAX lub MIN od razu wyświetlała się liczba, która jest aktualnie ustawiona na danym progu, a nie dopiero po zmianie jej wartości.

[ Dodano: 01-04-2017, 23:48 ]

Dodałem 4 przycisk, ale widocznie coś przeoczyłem. Temperatura się wyświetla ale nie da się wejść w tą zmianę tych progów.

#include <OneWire.h>
#include <DS18B20.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

//przyciski
#define UP 4
#define DOWN 5
#define ENTER 6
#define ENTEXIT 10

#define LED 8


//Numer pinu do ktorego podlaczasz czujnik
#define ONEWIRE_PIN 2

float temperatura = 0;

float liczba[2] = {0,0};  //progi temperatur

int prog = 0; //wartosc dla danego progu
int entexit = 0;

bool flaga = true;
//ostatnie klikniecia przyciskow
long last_up = 0; 
long last_down = 0;
long last_enter = 0;
long last_entexit = 0;

//adres czujnika
byte address[8] = {0x28, 0xFF, 0x9A, 0x26, 0x58, 0x16, 0x4, 0x42};

//Adres wyswietlacza
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);




void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);

 pinMode(ENTER, INPUT_PULLUP);
 pinMode(UP, INPUT_PULLUP);
 pinMode(DOWN, INPUT_PULLUP);
 pinMode(ENTEXIT, INPUT_PULLUP);



 sensors.begin();
 sensors.request(address);

 lcd.begin(16, 2);
 lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.setCursor(0, 0); //ustawienie kursora
 lcd.print("Temp: ");


}

/*void progi(float temperatura, float liczba[0], float liczba[1])
{
 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }

}*/
void loop() {
 // put your main code here, to run repeatedly:


    temperatura = sensors.readTemperature(address);
 sensors.request(address);

  if((digitalRead(ENTEXIT)==LOW) && (millis() - last_entexit > 200))
{
 if(entexit==0){entexit=1;}
 else{entexit = 0;}
 last_entexit = millis();

}
 if(entexit==0){

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Temp: ");
 lcd.setCursor(6, 0);
 lcd.print(temperatura);
 lcd.setCursor(12, 0);
 lcd.print("*C");

  delay(3000);

 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }

 }

 if(entexit == 1){
 if((digitalRead(ENTER)==LOW) && (millis() - last_enter > 200))
 {
   if(prog == 0)
   {
     prog = 1;

   }
   else
   {
     prog = 0;

   }
     last_enter = millis();
 }


 if(prog == 1){

   lcd.setCursor(0,0);
 lcd.print("MAX");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }
 if(prog ==0){

 lcd.setCursor(0,0);
 lcd.print("MIN");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }

 if(flaga!=false){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);

 flaga=false;
 }
 if(liczba[prog] < 100.0){
 if((digitalRead(UP)==LOW) && (millis() - last_up > 200))
 {

   liczba[prog]+=0.1;
   last_up = millis();

   flaga = true;}
  }


 if( 0 <= liczba[prog]){
 if((digitalRead(DOWN)==LOW) && (millis() - last_down > 200))
 { 

   liczba[prog]-=0.1;
   last_down = millis();
   flaga = true;}
 }
 }

}
Link do komentarza
Share on other sites

Zarejestruj się lub zaloguj, aby ukryć tę reklamę.
Zarejestruj się lub zaloguj, aby ukryć tę reklamę.

jlcpcb.jpg

jlcpcb.jpg

Produkcja i montaż PCB - wybierz sprawdzone PCBWay!
   • Darmowe płytki dla studentów i projektów non-profit
   • Tylko 5$ za 10 prototypów PCB w 24 godziny
   • Usługa projektowania PCB na zlecenie
   • Montaż PCB od 30$ + bezpłatna dostawa i szablony
   • Darmowe narzędzie do podglądu plików Gerber
Zobacz również » Film z fabryki PCBWay

Udało mi się zrobić takie coś. I teraz pomiar działa poprawnie, ale jak wchodze w zmianę progów to znowu tekst szybko miga.

#include <OneWire.h>
#include <DS18B20.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

//przyciski
#define UP 4
#define DOWN 5
#define ENTER 6
#define ENTEXIT 10

#define LED 8


//Numer pinu do ktorego podlaczasz czujnik
#define ONEWIRE_PIN 2

float temperatura = 0;
float temp =0;

float liczba[2] = {0,0};  //progi temperatur

int prog = 0; //wartosc dla danego progu
int entexit = 0;

bool flaga = true;
bool flaga2 = true;
//ostatnie klikniecia przyciskow
long last_up = 0; 
long last_down = 0;
long last_enter = 0;
long last_entexit = 0;
long last_check = 0;

//adres czujnika
byte address[8] = {0x28, 0xFF, 0x9A, 0x26, 0x58, 0x16, 0x4, 0x42};

//Adres wyswietlacza
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);




void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);

 pinMode(ENTER, INPUT_PULLUP);
 pinMode(UP, INPUT_PULLUP);
 pinMode(DOWN, INPUT_PULLUP);
 pinMode(ENTEXIT, INPUT_PULLUP);



 sensors.begin();
 sensors.request(address);

 lcd.begin(16, 2);
 lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.setCursor(0, 0); //ustawienie kursora
 lcd.print("Temp: ");


}

/*void progi(float temperatura, float liczba[0], float liczba[1])
{
 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }

}*/
void loop() {
 // put your main code here, to run repeatedly:


    temperatura = sensors.readTemperature(address);
 sensors.request(address);

  if((digitalRead(ENTEXIT)==LOW) && (millis() - last_entexit > 200))
{
 if(entexit==0){entexit=1;}
 else{entexit = 0;}
 last_entexit = millis();

}

if((millis() - last_check > 3000) && (temperatura!=temp)){

 temp=temperatura;

 last_check = millis();
 flaga2 = true;
}
 if(entexit==0 && flaga2 ==true){

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Temp: ");
 lcd.setCursor(6, 0);
 lcd.print(temp);
 lcd.setCursor(12, 0);
 lcd.print("*C");


 // delay(3000);

 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }
 flaga2 = false;
 }

 if(entexit == 1){
 if((digitalRead(ENTER)==LOW) && (millis() - last_enter > 200))
 {
   if(prog == 0)
   {
     prog = 1;

   }
   else
   {
     prog = 0;

   }
     last_enter = millis();
 }


 if(prog == 1){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("MAX");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }
 if(prog ==0){

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("MIN");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }

 if(flaga!=false){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);

 flaga=false;
 }
 if(liczba[prog] < 100.0){
 if((digitalRead(UP)==LOW) && (millis() - last_up > 200))
 {

   liczba[prog]+=0.1;
   last_up = millis();

   flaga = true;}
  }


 if( 0 <= liczba[prog]){
 if((digitalRead(DOWN)==LOW) && (millis() - last_down > 200))
 { 

   liczba[prog]-=0.1;
   last_down = millis();
   flaga = true;}
 }
 }

}
Link do komentarza
Share on other sites

No dobra tak zrobiłem, tylko co teraz z tym migającymi progami i wartościami na progach

#include <OneWire.h>
#include <DS18B20.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

//przyciski
#define UP 4
#define DOWN 5
#define ENTER 6
#define ENTEXIT 10

#define LED 8


//Numer pinu do ktorego podlaczasz czujnik
#define ONEWIRE_PIN 2

float temperatura = 0;
float temp =0;

float liczba[2] = {0,0};  //progi temperatur

int prog = 0; //wartosc dla danego progu
int entexit = 0;

bool flaga = true;
bool flaga2 = true;
//ostatnie klikniecia przyciskow
long last_up = 0; 
long last_down = 0;
long last_enter = 0;
long last_entexit = 0;
long last_check = 0;

//adres czujnika
byte address[8] = {0x28, 0xFF, 0x9A, 0x26, 0x58, 0x16, 0x4, 0x42};

//Adres wyswietlacza
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);




void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);

 pinMode(ENTER, INPUT_PULLUP);
 pinMode(UP, INPUT_PULLUP);
 pinMode(DOWN, INPUT_PULLUP);
 pinMode(ENTEXIT, INPUT_PULLUP);



 sensors.begin();
 sensors.request(address);

 lcd.begin(16, 2);
 lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.setCursor(0, 0); //ustawienie kursora
 lcd.print("Temp: ");


}

/*void progi(float temperatura, float liczba[0], float liczba[1])
{
 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }

}*/
void loop() {
 // put your main code here, to run repeatedly:


    temperatura = sensors.readTemperature(address);
 sensors.request(address);

  if((digitalRead(ENTEXIT)==LOW) && (millis() - last_entexit > 200))
{
 if(entexit==0){entexit=1;}
 else{entexit = 0;}
 last_entexit = millis();

}

if((millis() - last_check > 3000)){

 temperatura = sensors.readTemperature(address);
 sensors.request(address);

 last_check = millis();
 flaga2 = true;
}
 if(entexit==0 && flaga2 ==true){

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Temp: ");
 lcd.setCursor(6, 0);
 lcd.print(temperatura);
 lcd.setCursor(12, 0);
 lcd.print("*C");


 // delay(3000);

 if(temperatura > liczba[0] && temperatura < liczba[1])
 {
   digitalWrite(LED, HIGH);
   delay(200);
 }
 else
 {
   digitalWrite(LED, LOW);
   delay(200);
 }
 flaga2 = false;
 }

 if(entexit == 1){
 if((digitalRead(ENTER)==LOW) && (millis() - last_enter > 200))
 {
   if(prog == 0)
   {
     prog = 1;

   }
   else
   {
     prog = 0;

   }
     last_enter = millis();
 }


 if(prog == 1){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("MAX");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }
 if(prog ==0){

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("MIN");

 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);
 }

 if(flaga!=false){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.setCursor(10, 0);
 lcd.print(liczba[prog],1);

 flaga=false;
 }
 if(liczba[prog] < 100.0){
 if((digitalRead(UP)==LOW) && (millis() - last_up > 200))
 {

   liczba[prog]+=0.1;
   last_up = millis();

   flaga = true;}
  }


 if( 0 <= liczba[prog]){
 if((digitalRead(DOWN)==LOW) && (millis() - last_down > 200))
 { 

   liczba[prog]-=0.1;
   last_down = millis();
   flaga = true;}
 }
 }

}
Link do komentarza
Share on other sites

W którym miejscu to mam zmienić, bo przez wyświetlanie, rozumiem to

if(prog == 1)
 {
   if(flaga== true)
   {  
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("MAX");

     lcd.setCursor(10, 0);
     lcd.print(liczba[prog],1);

     flaga = false;
    }
 }
 if(prog ==0)
 {
    if(flaga== true)
    {  
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("MIN");

       lcd.setCursor(10, 0);
       lcd.print(liczba[prog],1);
       flaga = false;
    }
 }
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.