How to call void inside void loop

HI Hello everyone

I think here something is missing ?? :confused:

#include "LiquidCrystal.h"


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switch1 = 6;
const int switch2 = 7;
const int switch3 = 8;
const int led1 = 9;
const int led2 = 10;
const int led3 = 13;

void setup(){
  
  
  lcd.begin(16, 2);
pinMode(switch1,INPUT_PULLUP);
pinMode(switch2,INPUT_PULLUP);
pinMode(switch3,INPUT_PULLUP);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
void loop(){
  
  lcd.setCursor(0, 0);
  lcd.print("ready");
  if(digitalRead(switch1 =LOW)){
doorPin();
}
  if(digitalRead(switch2 =LOW)){
windowPin();
}
  if(digitalRead(switch3 =LOW)){
lightPin();
}

void doorPin(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("door open");
digitalWrite(led,LOW);
delay(1000)
digitalWrite(led,HIGH);
delay(1500)
}

void windowPin(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("window open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}

void lightPin(){
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("light open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}

if(digitalRead(switch1 =LOW)){Oops.

That, plus missing braces.

if(digitalRead(switch1 =LOW)){

Oops on top of an oops on top of an oops.

You don’t want to read PIN number (switch1 = LOW). You want to read PIN number switch1 and then compare that result to LOW. Check your parenthesis.

Also = is an assignment. For comparison you’d use ==

Also you’re missing the closing brace on loop so your functions (they’re called functions not voids, void is just the return type you happened to choose) are defined inside the loop function. You can’t define a function inside a function.

Go look at some examples and compare to your code.

As AWOL points out, you have missing braces.
If you use autoformat inside the editor, it makes it much easier to find mismatch braces.
CTRL-T on a PC autoformats.

LOGANTN:
I think here something is missing ?? :confused:

What is missing is a description of your problem. Does it not compile? Does it do something you don't expect it to do? We are not mind readers, we don't know what you want your project to do. Only you know that.

Also, here is the reference for digitalRead().

This line

if(digitalRead(switch1 =LOW)){

should be

if(digitalRead(switch1) == LOW){

and it is because that line is wrong that the call to doorPin() does not work

...R

HI , thank you for your answer

here new message and i can't call void

someone tells me the thing is i missed please

Arduino : 1.8.8 (Windows 7), Carte : "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\RAC\Documents\Arduino\sketch_feb01c\sketch_feb01c.ino: In function 'void loop()':

sketch_feb01c:33:9: error: 'doorPin' was not declared in this scope

 doorPin();

         ^

sketch_feb01c:36:11: error: 'windowPin' was not declared in this scope

 windowPin();

           ^

sketch_feb01c:39:10: error: 'lightPin' was not declared in this scope

 lightPin();

          ^

sketch_feb01c:42:15: error: a function-definition is not allowed here before '{' token

 void doorPin(){

               ^

sketch_feb01c:53:17: error: a function-definition is not allowed here before '{' token

 void windowPin(){

                 ^

sketch_feb01c:64:16: error: a function-definition is not allowed here before '{' token

 void lightPin(){

                ^

sketch_feb01c:73:1: error: expected '}' at end of input

 }

 ^

exit status 1
'doorPin' was not declared in this scope

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

We can't see your code.

Sorry

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int switch1 = 6;
const int switch2 = 7;
const int switch3 = 8;
const int led1 = 9;
const int led2 = 10;
const int led3 = 13;

void setup(){
  
  
  lcd.begin();
  lcd.backlight();
pinMode(switch1,INPUT_PULLUP);
pinMode(switch2,INPUT_PULLUP);
pinMode(switch3,INPUT_PULLUP);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
void loop(){
  
  lcd.setCursor(0, 0);
  lcd.print("ready");
  if(digitalRead(switch1 == LOW)){
doorPin();
}
  if(digitalRead(switch2 == LOW)){
windowPin();
}
  if(digitalRead(switch3 == LOW)){
lightPin();
}

void doorPin(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("door open");
digitalWrite(led,LOW);
delay(1000)
digitalWrite(led,HIGH);
delay(1500)
}

void windowPin(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("window open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}

void lightPin(){
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("light open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}
}

You are missing a } to close your loop before you declare the doorPin function.

LightuC:
You are missing a } to close your loop before you declare the doorPin function.

i close the loop }

and this is happen again

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int switch1 = 6;
const int switch2 = 7;
const int switch3 = 8;
const int led1 = 9;
const int led2 = 10;
const int led3 = 13;

void setup(){
  
  
  lcd.begin();
  lcd.backlight();
pinMode(switch1,INPUT_PULLUP);
pinMode(switch2,INPUT_PULLUP);
pinMode(switch3,INPUT_PULLUP);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
void loop(){
  
  lcd.setCursor(0, 0);
  lcd.print("ready");
  if(digitalRead(switch1 == LOW)){
dooropen();
}
  if(digitalRead(switch2 == LOW)){
windowopen();
}
  if(digitalRead(switch3 == LOW)){
lightPin();
}

void dooropen(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("door open");
digitalWrite(led,LOW);
delay(1000)
digitalWrite(led,HIGH);
delay(1500)
}

void windowopen(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("window open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}

void lightPin(){
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("light open");
digitalWrite(led,LOW);
delay(500)
digitalWrite(led,HIGH);
delay(1500)
}
}
Arduino : 1.8.8 (Windows 7), Carte : "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\RAC\Documents\Arduino\sketch_feb01c\sketch_feb01c.ino: In function 'void loop()':

sketch_feb01c:33:10: error: 'dooropen' was not declared in this scope

 dooropen();

          ^

sketch_feb01c:36:12: error: 'windowopen' was not declared in this scope

 windowopen();

            ^

sketch_feb01c:39:10: error: 'lightPin' was not declared in this scope

 lightPin();

          ^

sketch_feb01c:42:16: error: a function-definition is not allowed here before '{' token

 void dooropen(){

                ^

sketch_feb01c:53:18: error: a function-definition is not allowed here before '{' token

 void windowopen(){

                  ^

sketch_feb01c:64:16: error: a function-definition is not allowed here before '{' token

 void lightPin(){

                ^

exit status 1
'dooropen' was not declared in this scope

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

You're trying to define all your functions inside of the loop function. You can't do that. Type ctrl-t in the IDE and note how things line up.

BTW, Please stop calling them "voids" they are NOT "voids". They are FUNCTIONS!