Arduino Class "does not name a type"

Hello there, I am currently making a class in order to gain control over my LCD.
Here is the code:
Arduino_Marquee.h

#ifndef Arduino_Marquee_h
#define Arduino_Marquee_h

#include "Arduino.h"
#include <LiquidCrystal.h>

class Arduino_Marquee{
public:
  int max_string_length;
  int speed;
  
  char* text;
  
  Arduino_Marquee(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW);
  
  void marquee_init();
  void marquee_draw();
private:
  LiquidCrystal lcd(int, int, int, int, int);

  int lcd_collumn;
  int lcd_row;

  int rs;
  int enable;
  int d4;
  int d5;
  int d6;
  int d7;
};

#endif

Arduino_Marquee.cpp

#include "Arduino.h"
#include "Arduino_Marquee.h"
#include <LiquidCrystal.h>

Arduino_Marquee::Arduino_Marquee(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW){
  rs = RS;
  enable = ENABLE;
  d4 = D4;
  d5 = D5;
  d6 = D6;
  d7 = D7;

  lcd_collumn = LCD_COLLUMN;
  lcd_row = LCD_ROW;
}

void Arduino_Marquee::marquee_init(){
  lcd(rs, enable, d4, d5, d6, d7);
  lcd.begin(lcd_collumn, lcd_bar);
}

void Arduino_Marquee::marquee_draw(){
  for(int m = 0; m < lcd_collumn + max_string_length; m ++){
    for(int c = 0; c < lcd_row; c ++){
      for(int i = 0; i < max_string_length; i ++){
        lcd.setCursor(16 + i - m, c);
        lcd.print(text[c][i]);
      }
    }
    delay(500);
    lcd.clear();
  }
}

The error comes in "LiquidCrystal lcd(int, int, int, int, int);" , which is "LiquidCrystal does not name a type"
I need to control lcd inside my class.

So, I would expect some help from people here, regarding how can I make my class work.

Thank you in advance :slight_smile:

What is in your main sketch? Is that the only error message?

What is the intention of this line anyway?

private:
  LiquidCrystal lcd(int, int, int, int, int);   // <---- what is this doing?

Member objects are declared like other variables

private:
    LiquidCrystal lcd;

The initialization of those objects happens at constructor time, with a syntax that looks like this:

Arduino_Marquee::Arduino_Marquee(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW)
: lcd(RS, ENABLE, D4, D5, D6, D7) {

... more code ...

}

It's ok instead to save the rows and columns values and use them later when calling lcd.begin(). The reason is begin() is a "normal" method of the LiquidCrystal class, not its constructor.

Also a note about coding style: capital letters are usually used for constants and #defined symbols...

Anyway, I'd initialize the lcd object in the main sketch and just pass a pointer to it to the Marquee class, but that's just how I'd do it... :slight_smile:

Why don't you just extend the LiquidCrystal class with your additional method ?

You can have a philosophical discussion when it's appropriate to embed an object and when to derive from a base class,
IMHO here the approach class Arduino_Marquee:public LiquidCrystal{} is more appropriate.

I understand you rely on setting the public: char* text; variable prior to calling marquee_draw();,
which is intended to block your loop quite a while... :~

Inside marquee_draw() your

        lcd.print(text[c][ i  ]);

won't compile.
Instead of fixing the syntax error, I think it's a good idea to rethink your design in general, sorry :wink:

Edit: hope it's clearer now. Fixed the [ i ] issue

Okay, it is actually my bad habit for not commenting the code. :frowning:
I am using the very basic LCD with 16 columns and 2 rows.
So according to LiquidCrystal.h (int, int, int, int, int) will refers to (rs, enable, d4, d5, d6, d7) respectively.

tuxduino:
Member objects are declared like other variables

private:

LiquidCrystal lcd;




The initialization of those objects happens at constructor time, with a syntax that looks like this:



Arduino_Marquee::Arduino_Marquee(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW)
: lcd(RS, ENABLE, D4, D5, D6, D7) {

... more code ...

}




It's ok instead to save the rows and columns values and use them later when calling lcd.begin(). The reason is begin() is a "normal" method of the LiquidCrystal class, not its constructor.

Also a note about coding style: capital letters are usually used for constants and #defined symbols...

Anyway, I'd initialize the lcd object in the main sketch and just pass a pointer to it to the Marquee class, but that's just how I'd do it... :-)

I have change the .cpp files a bit to

(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW):lcd(RS, ENABLE, D4, D5, D6, D7)

The error returned still the same which is "LiquidCrystal does not name a type"

Actually I want make a class to make a marquee effect for an LCD, so in my humble opinion it will be still the same if I pass the initialization of the LCD outside with the marquee looping and just put the variable inside.

michael_x:
Why don't you just extend the LiquidCrystal class with your additional method ?

You can have a philosophical discussion when it's appropriate to embed an object and when to derive from a base class,
IMHO here the approach class Arduino_Marquee:public LiquidCrystal{} is more appropriate.

I understand you rely on setting the public: char* text; variable prior to calling marquee_draw();,
which is intended to block your loop quite a while... :~

Inside marquee_draw() your

        lcd.print(text[c][ i  ]);

won't compile.
Instead of fixing the syntax error, I think it's a good idea to rethink your design in general, sorry :wink:

Edit: hope it's clearer now. Fixed the [ i ] issue

I have tried the "extends" method in my code, when I compile it, it always return an error "Expected class name before '{' token".

About the lcd.print(text[c][i]); I have no problem compiling it in the previous sketch that I made, I mean firstly I made a sketch without a class, and it is works fine.

So any other idea?

I am sorry for the late reply but I am very thankful to your reply. :slight_smile:

n0talentGEEK:

[quote author=Nick Gammon link=topic=122741.msg923115#msg923115 date=1347583027]
What is the intention of this line anyway?

private:

LiquidCrystal lcd(int, int, int, int, int);   // <---- what is this doing?

Okay, it is actually my bad habit for not commenting the code. :frowning:
I am using the very basic LCD with 16 columns and 2 rows.
So according to LiquidCrystal.h (int, int, int, int, int) will refers to (rs, enable, d4, d5, d6, d7) respectively.

[/quote]

Well, no it won't. How can it be passing in (rs, enable, d4, d5, d6, d7) when you just have (int, int, int, int, int)?

I have change the .cpp files a bit to

(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW):lcd(RS, ENABLE, D4, D5, D6, D7)

The error returned still the same which is "LiquidCrystal does not name a type"

Can you post the amended code please.

The error returned still the same which is "LiquidCrystal does not name a type"

I suspect you still don't get the difference between constructing an object and calling a method on it...

Please have a look at the code here:

http://arduino.cc/en/Tutorial/LiquidCrystal

The following line creates an object named "lcd" by calling LiquidCristal's constructor (a constructor looks like a function and has the same name as the class):

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

This line instead calls the begin() method on the previously created object "lcd":

lcd.begin(16, 2);

HTH

Well, no it won't. How can it be passing in (rs, enable, d4, d5, d6, d7) when you just have (int, int, int, int, int)?

I have change the .cpp files a bit to

(int RS, int ENABLE, int D4, int D5, int D6, int D7, int LCD_COLLUMN, int LCD_ROW):lcd(RS, ENABLE, D4, D5, D6, D7)

The error returned still the same which is "LiquidCrystal does not name a type"

Can you post the amended code please.
[/quote]

Oh okay I am sorry I wrongly look at the tutorial.

http://pastebin.com/GJNYS7TC The .cpp file
http://pastebin.com/ixUfRq90 The .h file

Which is now I get an error "Arduino_Marquee has not been declared"

tuxduino:

The error returned still the same which is "LiquidCrystal does not name a type"

I suspect you still don't get the difference between constructing an object and calling a method on it...

Please have a look at the code here:

http://arduino.cc/en/Tutorial/LiquidCrystal

The following line creates an object named "lcd" by calling LiquidCristal's constructor (a constructor looks like a function and has the same name as the class):

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

This line instead calls the begin() method on the previously created object "lcd":

lcd.begin(16, 2);

HTH

Well maybe you correct, I still do not get several term in programming. Well in my opinion LiquidCrystal lcd will somewhat make another object named lcd that can return all function from Liquid.

Well maybe you correct, I still do not get several term in programming. Well in my opinion LiquidCrystal lcd will somewhat make another object named lcd that can return all function from Liquid.

(btw, I didn't mean to be rude) You're right, LiquidCrystal lcd(...) will in fact "make" a LiquidCrystal object, on which you can call LiquidCrystal methods. Bottom line is, just create one lcd object at the beginning of the sketch, and use that through the whole program.

HTH