does not name a type

I have a feeling that this is simply a noob error. I need a 2nd pair of eyes. Thanks.

error: ‘RGBLED’ does not name a type

RGBLED.h

#ifndef RGBLED_h
#define RGBLED_h

class RGBLED
{
   public:
    RGBLED (byte, byte, byte);
    void write(byte, byte, byte);
  
  
  private:
    byte pin_grn, pin_red, pin_blu;
    byte val_grn, val_red, val_blu;
  
};

#endif

RGBLED.cpp

#include "WProgram.h"
#include "RGBLED.h"


RGBLED::RGBLED(byte pin_r, byte pin_g, byte pin_b)
{
  pin_red = pin_r;
  pin_grn = pin_g;
  pin_blu = pin_b;  

  val_red = val_grn = val_blu = 0;
  
  pinMode(pin_red, OUTPUT);
  pinMode(pin_grn, OUTPUT);
  pinMode(pin_blu, OUTPUT);
  
}

void RGBLED::write(byte val_r, byte val_g, byte val_b)
{
  analogWrite(pin_red, val_r);  
  analogWrite(pin_grn, val_g);
  analogWrite(pin_blu, val_b);
  
  val_red = val_r;
  val_grn = val_g;
  val_blu = val_b;
  
}

The sketch

#include <RGBLED.h>

#define PIN_GRN 10
#define PIN_RED 9
#define PIN_BLU 11

RGBLED rgb(PIN_RED, PIN_GRN, PIN_BLU);

void setup()
{  
  //rgb.write(255, 255, 255);
}

void loop()
{
  
}

The #include "WProgram.h" needs to be in the .h because that is how the Arduino knows what a byte is.

I think it's just a bit confused

:)

This is the new RGBLED.h file:

#ifndef RGBLED_h
#define RGBLED_h

#include "WProgram.h>"

class RGBLED
{
   public:
    RGBLED (byte, byte, byte);
    void write(byte, byte, byte);
  
  
  private:
    byte pin_grn, pin_red, pin_blu;
    byte val_grn, val_red, val_blu;
  
};

#endif

Same error message

It compiles here. Try deleting the .o file.

#include "WProgram.h>"

should be:

#include "WProgram.h"

#include "WProgram.h>"

yeah that was just n00b. I initially spelt it right, but that didn’t work so i tried <WProgram.h> just for shits, but surely that wasn’t right, so the spelling error is a result of my incorrect attempt to change it back.

The problem was in my sketch:

#include <RGBLED.h> should have been #include “RGBLED.h”

#include <RGBLED.h> should have been #include “RGBLED.h”

As said before, your exact code compiles if the #include “WProgram.h” is placed inside the header. :slight_smile:

[edit]I had to emphesize this so that people who google and get here, know that the error was not the syntax for inclusion, but the location. Additionally, if you deleted the .o file, I think that was ultimately was what made it compile.

PostScriptum: Feel free to add this library in the Hardware Abstracion Library List[/edit]

As a comment on the difference between #include “Foo.h” and #include <Foo.h> for include statements: if it’s a header file that is part of a library, and thus in the library directories, use <>; if it’s a header file that’s a part of your own sketch, use “”.

It’s partly a matter of style, as the only difference is whether or not it will look in the same directory as the source file that is including it. It won’t hurt anything to say #include “WProgram.h” (even in your library’s header) but the correct way would be with <> brackets. It just clues the reader in to whether the header is yours or standard.

As AlphaBeta says, you need to include WProgram.h in all your headers, even library headers, because it defines core Arduino datatypes. The only time you don’t need it is in your main tab of your sketch, because the Arduino build scheme will add it for you.