Pages: [1]   Go Down
Author Topic: Class constructor not executing  (Read 330 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi hope this is not a silly question
In the following code the class constructor does not appear to do anything.
I expect to see on the graphics display attached to my Mega 1280 "Hello foo" followed, after a few seconds, by "Hello bar"
I do not see "Hello foo"  but I do see "Hello bar"

can anyone help please

Code:
//TR6

#include "TR6Display.h"
#include "ks0108.h"   
#include "Arial14.h"     

TR6Display TR6_Display();

void setup()
{
        delay(2000);
        GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
        delay(2000);
        GLCD.SelectFont(Arial_14);
        GLCD.GotoXY(20, 2);
        GLCD.Puts("Hello bar");

}

void loop()
{
}


Code:
//TR6Display.h


#ifndef TR6Display_h
#define TR6Display_h

class TR6Display
{
public:
TR6Display();
};

#endif


Code:
//TR6Display.cpp

#include "Wprogram.h"
#include "TR6Display.h"
#include "ks0108.h"
#include "Arial14.h"

TR6Display::TR6Display()
{
        delay(2000);
        GLCD.Init(NON_INVERTED);
       GLCD.ClearScreen();
        delay(2000);
        GLCD.SelectFont(Arial_14);
        GLCD.GotoXY(20, 2);
        GLCD.Puts("Hello foo");

}
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some information here.

Short answer, "Don't do that". You can't rely on any of the hardware being setup properly before constructors for global objects are called. Rework your class with a begin() or init() member function that does the initialisation, and call it in setup().
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your reply crimony - I'll take your advice

blt
Logged

Pages: [1]   Go Up
Jump to: