Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <IRremote.h>

int RECV_PIN = 4; //DIGITAL PIN USED BY KY-022 PH
 
IRrecv irrecv(RECV_PIN); //PASS THE PARAMETER TO THE FUNCTION irrecv
 
decode_results results; //VARIABLE STORING RESULTS (IR SIGN RECEIVED)
int ledb = 10;
int ledg = 11;
int ledy = 12;
int ledr = 13;


int LED = 8; // Pino no qual o LED está conectado
int LDR = A0; // Pino no qual o LDR está conectado
int entrada = 0; // Variável que receberá o valor lido do LDR

int ledPin= 7;   // choose the pin for the LED
int inputPin= 2;  // choose the input pin (for PIR sensor)
void setup()
{
Serial.begin(9600); // Iniciar e definir a velocidade de comunicação da porta serial
pinMode(LED, OUTPUT);
  
pinMode(ledPin, OUTPUT);  // declare LED as output
pinMode(inputPin, INPUT);  // declare sensor as input
  
  {
  Serial.begin(9600); //INITIALIZES THE SERIAL
  irrecv.enableIRIn(); //INITIALIZES IR SIGNAL RECEPTION
  pinMode(ledr,OUTPUT);
  pinMode(ledy,OUTPUT);
  pinMode(ledg,OUTPUT);
  pinMode(ledb,OUTPUT);
}
 
long bts[]={16582903,16615543,16599223,16591063};
int leds[]={10,13,12,11};
}
void disparaLed(int led)
{
  digitalWrite(led, HIGH); // activates digital pin 13
  delay(1000);            // wait for a second
  digitalWrite(led, LOW);  // disable digital pin 13
}
void loop()
{
int value= digitalRead(inputPin);  // read input value
entrada = analogRead(LDR);
Serial.println(entrada); // Valor que será exibido no Serial Monitor
if (entrada < 500)
{
digitalWrite(LED, HIGH); // Acender o LED
}
else
{
digitalWrite(LED, LOW); // Apagar o LED
delay(100);
}
  if (value == HIGH)     // check if the input is HIGH
{
digitalWrite(ledPin, HIGH);  // turn LED ON
delay(5000);
digitalWrite(ledPin, LOW);  // turn LED OFF
}
else
{
digitalWrite(ledPin, LOW);  // if no motion then keep LED OFF
}
  {
  //CAPTURE THE GO SIGN

	 if (irrecv.decode(&results)) {
        for(int i=0;i<4;i++)
        {
           if (bts[i]==results.value)  {
                disparaLed(leds[i]);         
                i = 4;
           }
        }   
      Serial.println(results.value);
      irrecv.resume(); //LOOKS FORWARD TO RECEIVING A NEW IR SIGN
  	}  
	delay(10);
}
}



 In function 'void loop()':
78:16: error: 'bts' was not declared in this scope
78:16: note: suggested alternative: 'gets'
79:28: error: 'leds' was not declared in this scope
79:28: note: suggested alternative: 'ledr'
 exit status 1


What I have tried:

i dont know what this mean
help me
Posted
Updated 14-May-21 7:47am

When you declare anything, it has a scope - the area it exists within.
If you declare it within a set of curly brackets that limits it's scope - it is available within the brackets, but not outside.
For example, if you declare a function with a variable, then the brackets delimiting the function body define where the variable can be used:
C++
... x is not available here
void foo()
   {
   int x;
   ... x is available here
   }
... x is not available here
We call this a "local variable" - it is local to the function.

bts is declared in the body of your setup function, and so isn't available inside your loop function.

Same thing for the other error.
 
Share this answer
 
Further to what KarstenK and OriginalGriff had said about scope, if you indent your code better, it becomes clearer what's going on e.g.
C++
void setup()
{
    Serial.begin(9600); // Iniciar e definir a velocidade de comunicação da porta serial
    pinMode(LED, OUTPUT);
  
    pinMode(ledPin, OUTPUT);  // declare LED as output
    pinMode(inputPin, INPUT);  // declare sensor as input
  
    {
        Serial.begin(9600); //INITIALIZES THE SERIAL
        irrecv.enableIRIn(); //INITIALIZES IR SIGNAL RECEPTION
        pinMode(ledr,OUTPUT);
        pinMode(ledy,OUTPUT);
        pinMode(ledg,OUTPUT);
        pinMode(ledb,OUTPUT);
    }
 
    long bts[]={16582903,16615543,16599223,16591063};
    int leds[]={10,13,12,11};
}

We can now clearly see that bts is declared within the scope of the setup() function, so is not available to code outside that function. Looking at this code, I think you meant to declare both bts and leds at the file level, but the indentation style of the posted code makes it hard to see that it they are actually defined only within the setup() function.

Using good indentation also reveals an odd use of a local block, from before Serial.begin() to after pinMode(ledb,OUTPUT) for no apparent reason. That isn't an error at all, and a code formatting tool will indent the contained code similarly to what I have here, which may be the intention, but its not required here, and would not normally be done.

Check your compiler documentation and see how you can turn up the warning levels. You should then get warnings from the compiler that both bts and leds are unused, which might have been another clue as to the error reported in your question.
 
Share this answer
 
Read some C++ reference about scope.

In programming or computer science it is best to know the theoretics about the tool which are using. As in any science: "knowledge is power" ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900