SoftwareSerial in a class

To learn about Arduino and OOP within this environment, I've created a simple project.

Reading from some Sharp IRs and display the values on a Parallax Serial LCD screen. The project ran ok when the code all was in a single .ino file.

However, when wrapping up the Serial LCD in a class, I'm having issues with my constructor. If I comment out the variable declaration and instanciation, my project runs fine (LED on 13 blinks away and I get Serial.println output). If my object is instanciated, the board locks up (no blinking, and Windows plays the USB disconnected sound).

.ino in part

#include <SoftwareSerial.h>
#include "SharpSensor.h"
#include "SerialLCD.h"

SerialLCD screen = SerialLCD();

When that last line is commented out, it works fine.

Serial.h

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

class SerialLCD
{
public:
  SerialLCD();
  void clearScreen();
  void lineWrap();
  void writeString(String data);
  void writeLineString(String data);

private:
  SoftwareSerial mySerial;
};

SerialLCD.cpp

#include "SerialLCD.h"

SerialLCD::SerialLCD() : 
mySerial(255, 1)
{
  pinMode(1, OUTPUT);
  digitalWrite(1, HIGH);

  mySerial.begin(9600);
  delay(100);

  mySerial.write(12);                 // Clear             
  mySerial.write(17);                 // Turn backlight on
  delay(5);                           // Required delay
  mySerial.print("Hello, world...");  // First line
  mySerial.write(13);                 // Form feed
  delay(5);                           // Required delay
  mySerial.print("from Parallax!");   // Second line
}

void SerialLCD::clearScreen()
{
  mySerial.write(12);
  delay(5);
}
void SerialLCD::lineWrap()
{
  mySerial.write(13);
  delay(5);
}
void SerialLCD::writeString(String data)
{
  mySerial.print(data);
}
void SerialLCD::writeLineString(String data)
{
  writeString(data);
  lineWrap();  
}

Thanks

Don't run actual program code in the constructor, use the begin() method or some such. Constructors for global
variables are called too early, just setup the instance variables but don't do anything!

.ino in part

Wrong. Post ALL of the .ino file. There may be (plenty) of other things wrong, besides the major problem that MarkT points out.

MarkT:
Don't run actual program code in the constructor, use the begin() method or some such. Constructors for global
variables are called too early, just setup the instance variables but don't do anything!

That did it .. I just saved the pin in my in constructor, and moved everything else to an "init()" method.

Thanks!

I just saved the pin in my in constructor, and moved everything else to an "init()" method.

Perhaps you've used Serial.begin() or Ethernet.begin()? There's a clue there...