Go Down

Topic: 'irrecv' does not name a type (Read 858 times) previous topic - next topic

Helghallen

Hi:

I have searched and tried the various reinstalling libraries and such to no avail. I have code that will use irrecv.enableIRIn(); // Start the receiver with no issues, but in my new sketch it gives me the above error and I am not sure why.

My code is:
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>





#include <Adafruit_NeoPixel.h>

int IRpin = 02;  // pin for the IR sensor
IRrecv irrecv(IRpin);
decode_results results;
#define PIN 1


#ifdef __AVR__
  #include <avr/power.h>
  #endif
boolean LEDon = true; // initializing LEDon as true

Adafruit_NeoPixel strip = Adafruit_NeoPixel(36
, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
    irrecv.enableIRIn(); // Start the receiver

}

void loop()
{
       uint32_t gold = strip.Color(255, 255, 0);
         uint32_t blue = strip.Color(0, 0, 255);
         uint32_t green = strip.Color(0, 255, 0);
   
  if (irrecv.decode(&results))
    {
     
      irrecv.resume();   // Receive the next value
    }
 
  switch(results.value)
 {

  case 16738455:
  for( int i = 0; i<36; i++){
        strip.setPixelColor(i, blue);
        strip.show();
    }    // Solid Blue
  break;
 
  case 16724175:
   for( int i = 0; i<36; i++){
        strip.setPixelColor(i, green);
        strip.show();
    }   // Solid Green
  break;
 
  case 16718055:
  for( int i = 0; i<36; i++){
        strip.setPixelColor(i, gold);
        strip.show();
    }   // Solid Gold
  break;
 
 
 
  }
 
}


My goal is to make a neopixel ring turn to various colors and styles with the IR remote but this code won't compile and I am not sure why.

Thanks for any help

TolpuddleSartre

#1
Mar 29, 2018, 08:07 pm Last Edit: Mar 29, 2018, 08:09 pm by TolpuddleSartre
Look where your setup function ends.

That means that this
Code: [Select]
irrecv.enableIRIn(); // Start the receiver
is not in a function.
C++ doesn't like that.

INTP

Yep.

Also, my sketches have wire.h included for some reason.

Helghallen

Look where your setup function ends.

That means that this
Code: [Select]
irrecv.enableIRIn(); // Start the receiver
is not in a function.
C++ doesn't like that.
I am not sure what you mean by that. I looked at the other sketch where this works and I don't see a difference?

#include <IRremote.h>

int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results))
    {
      Serial.println(results.value, DEC); // Print the Serial 'results.value'
      irrecv.resume();   // Receive the next value
    }
 
 
}

INTP

Your setup:

Code: [Select]
void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}




That setup:

Code: [Select]
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

Helghallen

Holy cow. That worked. I am so new to all this. But I understand now what I was doing wrong. I just moved the problem line into the same bracket thing as the strip commands.

thank you so much.

:( but now in trying to upload to my Gemma, it says the sketch is too big. I am too new at this that I am not sure what is making it that big?

INTP

Let's make sure you understand this, and it does bear belaboring.

Code: [Select]


void setup()
{

//setup stuff goes here

}




//you put stuff here


void loop()
{

//looping stuff goes here

}





And your code is large because of the included libraries.

Helghallen

Yes it does. Learning as I go and sometimes the old noggin doesn't quite put two and two together and get 4.

Go Up