So i need to be able to switch betwen parts of code with only one button how do i can do this to work with more than 2 parts of code. Actualy i made sucesfully switching betwen 2 codes.
code dont look too much into it, its garbage
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
DHT dht;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define DHT11_PIN 2
#define ONE_WIRE_BUS_1 0
#define ONE_WIRE_BUS_2 1
int max = 2;
int min = 2;
int maxt = 23;
int mint = 21;
int inp1,inp2,inp3,inp4,inp5,humidity;
OneWire oneWire_left(ONE_WIRE_BUS_1);
OneWire oneWire_right(ONE_WIRE_BUS_2);
DallasTemperature sensor_left(&oneWire_left);
DallasTemperature sensor_right(&oneWire_right);
int zmint,zmaxt,zmin,zmax,zmien;
bool x;
int tempz,tempa;
unsigned long aktualny = 0;
unsigned long poprzedni= 0;
unsigned long roznica = 0;
byte menus=2;
void setup() {
// put your setup code here, to run once:
dht.setup(DHT11_PIN);
Serial.begin(9600);
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
lcd.begin(16,2);
sensor_right.begin();
sensor_left.begin();
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(7,OUTPUT);
zmien =3;
}
void loop() {
// put your main code here, to run repeatedly:
aktualny = millis();
roznica = aktualny - poprzedni;
if (roznica >= 5000UL) {
unsigned long x;
//Zapamietaj aktualny czas
x = millis();
Serial.println(x);
sensor_right.requestTemperatures();
sensor_left.requestTemperatures();
humidity = dht.getHumidity();
x = millis();
Serial.println(x);
poprzedni = aktualny;
//Wyslij do PC
Serial.println(aktualny);
}
float temp_right;
float temp_left;
temp_right = sensor_right.getTempCByIndex(0);
temp_left = sensor_left.getTempCByIndex(0);
int averge = (temp_right + temp_left)/2;
int left = temp_left;
int right = temp_right;
if(averge +max >= maxt)
{
Serial.println("OTWORZYC");
inp2=1;
inp1=0;
}
if(averge +min <= mint)
{
Serial.println("ZALACZYC");
inp1=1;
inp2=0;
}
delay(200);
if(digitalRead(5)==LOW) //this works with no porblems
{
if(menus==1)
{
menus=2;
lcd.clear();
}
else
{
menus=1;
lcd.clear();
}
}
if(menus== 1)
{
lcd.print("T1 ");
lcd.print(temp_left,1);
lcd.print("");
lcd.print(" T2 ");
lcd.print(temp_right,1);
lcd.print("");
lcd.setCursor(0,1);
lcd.print(inp1);
lcd.print(" ");
lcd.print(inp2);
lcd.print(" ");
lcd.print(inp3);
lcd.print(" ");
lcd.print(inp4);
lcd.print(" ");
lcd.print(inp4);
lcd.print(" ");
lcd.print("RH-");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(0,0);
}
if(menus==2)
{
if(digitalRead(6)==1) // here i have problem
{
switch(zmien)
{
case 3:{
if(digitalRead(3)==1)
{
zmin +=1;
}
if(digitalRead(4) == 1)
{
zmin -=1;
}
if(digitalRead(2) ==0)
{
min =zmin;
}
zmien=4;
}
break;
case 4:
if(zmien ==4)
{
if(digitalRead(3)==1)
{
zmax +=1;
}
if(digitalRead(4) == 1)
{
zmax -=1;
}
if(digitalRead(2) ==0)
{
max =zmax;
}
zmien=1;
}
break;
}
}
lcd.setCursor(5,1);
lcd.print(" ");
lcd.setCursor(11,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(mint);
lcd.print("||");
lcd.print(maxt);
lcd.print("||");
lcd.print(min);
lcd.print("||");
lcd.print(max);
lcd.setCursor(0,1);
lcd.print(zmint);
lcd.print("||");
lcd.print(zmaxt);
lcd.print("||");
lcd.print(zmin);
lcd.print("||");
lcd.print(zmax);
lcd.setCursor(0,0);
}
}