help please, 2 projects in one

Hello,

I would like to combine these two projects.
When a button is pressed the LCD display changes from "Visitor counter" and displays "temperature", and when the button is reset it returns to "Visitor counter".I
f you can help me. It is only now that I have started using Arduino.
Thank you.

#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);
#define in 14
#define out 19
#define relay 2
int count=0;
void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}

void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}
void loop()
{  
  
  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();
  
  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }
  
  else
    digitalWrite(relay, HIGH);
  
}

and

#include

LiquidCrystal lcd (13,12,11,10,9,8);

float value;

int cel;

int far;

int output1=8;

int output2=9;

int output3=10;

void setup()

{

Serial.begin(9600);

lcd.begin(16,2);

pinMode(output1,OUTPUT);

pinMode(output2,OUTPUT);

pinMode(output3,OUTPUT);

digitalWrite(output1,LOW);

digitalWrite(output2,LOW);

digitalWrite(output3,LOW);

}

void loop()

{

value=analogRead(A0);

value = (value*5000)/1024;

cel=value/10;

far = (cel*9)/5;

far = far+32;

lcd.setCursor(0,0);

lcd.print("Temperat");

lcd.setCursor(0,1);

lcd.print(cel);

lcd.print(char(223));

lcd.print("C");

lcd.setCursor(4,1);

lcd.print(",");

lcd.setCursor(5,1);

lcd.print(far);

lcd.print(char(223));

lcd.print("F");

lcd.setCursor(9,0);

lcd.print("|");

lcd.setCursor(9,1);

lcd.print("|");

lcd.setCursor(10,0);

lcd.print("ADC is");

lcd.setCursor(10,1);

lcd.print(value);

if(cel>=28)

{

digitalWrite(output1,HIGH);

digitalWrite(output2,LOW);

digitalWrite(output3,LOW);

}

if(cel>=30)

{

digitalWrite(output2,HIGH);

digitalWrite(output1,LOW);

digitalWrite(output3,LOW);

}

if(cel>=33)

{

digitalWrite(output2,LOW);

digitalWrite(output3,HIGH);

digitalWrite(output1,LOW);

}

if(cel<=27){

digitalWrite(output2,LOW);

digitalWrite(output3,LOW);

digitalWrite(output1,LOW);

}

delay(100);

}


}

First tell us that both programs run correctly and produce proper results.

Paul

This Simple Merge Demo may help.

Before trying to merge the programs go through each of them carefully to make sure they are not trying to use the same resource - for example an I/O pin. If you find conflicts change something in one of the separate programs and make sure it still works as a separate program with the change.

...R

I simulated the two programs and it works.
I have attached.

gabrielenacsu1997:
I simulated the two programs and it works.
I have attached.

So you only want to simulate the combination of the two codes, right?

Paul

Yes, both programs work.
But at the push of a button or two, the LCD display changes.
At a press of the button to display the temperature, and at another press "Visitato counter"

Sorry for my english, is bad

I have attached.

up !

I want to combine the two codes with the push of a button I want to change the LCD display. At the first press to display "Visitor counter" and at another press "Temperature"