weatherstation button problem!!!

Hi.

In my weather station i have a little problem.. i wrote a code to swith temperature , humidity and pressure on display by pressing the button.. and if the button reaches 3 presses it will show the temperature again...but it dont work.. can u help me please?

CODE:
#include <LiquidCrystal.h> //pripojíme knižnicu pre LCD 16x2
#include <Wire.h> // pripojíme knižnicu pre prepojovacie káble
#include <Adafruit_Sensor.h> // pripojíme knižnicu pre senzory
#include <Adafruit_BMP085_U.h> // pripojíme knižnicu pre senzor BMP180( BMP085 )
#include <cactus_io_SHT31.h> // pripojíme knižnicu pre senzor SHT31

//Prepojenie BMP180 a SHT31 k Arduinu UNO

//Pripojíme SCL na analógový vstup A5
//Pripojíme SDA na analógový vstup A4
//Pripojáme VDA na 3,3 Volta
//Pripojím GND na GND Arduino
int set=7;
int backLight = 9;
float temperature;
int stav=0;
int poslednyStav=0;
int p=0;
int mode=0;

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // priradíme vývody
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // zadáme vývody na LCD monitore

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

cactus_io_SHT31 sht31;

void setup()
{
Serial.begin(9600); //Priradíme Serial Monitor
pinMode(backLight,HIGH);
digitalWrite(backLight,HIGH);

if(!bmp.begin())
{
// cyklus na ten prípad ak by bol nijaky problem so senzorom BMP180
lcd.print("NO BMP180 DETECTED!");
while(1);
}

// cyklus na ten prípad ak by bol nijaky problem so senzorom SHT31
if (!sht31.begin()) {
lcd.println("NO SHT31 DETECTED!"); //
while(1) ;
}

}

void loop(){
sensors_event_t event; // vytvoríme nove udalosti
bmp.getEvent(&event);
if (event.pressure){
}
else
{
lcd.println("Sensor error"); // Ak nastane niaka chyba pri meraní tlaku vypíše nám na obrazovku CHYBA!
}

switch (mode){
default :do{
bmp.getTemperature(&temperature); // načítame hodnotu teploty zo senzora BMP180
lcd.setCursor(0,0); // nastvíme kurzor na začiatok prvého riadku
lcd.print("T:");
lcd.print(temperature); // vypíše nám teplotu s nepresnosťou +/- 2
lcd.print(char(178)); // znak
lcd.print("C");
mode = pocitadlo ();
}while(mode==0);

case 1:do{
lcd.clear();
lcd.print(" H:");
lcd.print(round(sht31.getHumidity())); // načíta hodnotu vlhkosti zo senzora SHT31 s nepresnostou +/- 2
lcd.print("%");
mode = pocitadlo();
}while (mode==1);

case 2:do{
lcd.clear();
lcd.setCursor(0,1); // nastavíme kurzor na začiatok druhého riadku
lcd.print("P:");
lcd.print(event.pressure); // načítame hodnotu tlaku zo senzora BMP180
lcd.print("hPa");
mode = pocitadlo();
}while (mode==2);
}
}

int pocitadlo(){
stav= digitalRead(set);
if (stav != poslednyStav){
if (stav = LOW){
p++;
}
}
poslednyStav= stav;
if(p==3){
p = 0;}
return p;}

tryharduz.ino (2.64 KB)

Should your switch/cases have some breaks somewhere ?

it show the temperature only but when i press the button nothing happens

so i just need to remove cases and let it in the loop?

majrashi:
so i just need to remove cases and let it in the loop?

One very good reason to use switch/case is to ensure that only the required code for the current state of the program is executed. However, the program needs to know where the code to be executed ends, hence the need for a break; command at the end of the code block for each case.

can u add it into my code?? i dont realy understand a lot what u said..

I also don't think p is going to ever change here since if(stav=LOW) will never be true. Might be why your button doesn't work.

stav = digitalRead(set);
if (stav != poslednyStav) {
if (stav = LOW) {
p++;
}
}

Did you mean if (stav == LOW)?