Go Down

Topic: SoftwareSerial child class to drive a netmedia serial lcd (Read 829 times) previous topic - next topic

tuxduino

Hi all,
    I've got this serial lcd:

http://www.robot-italy.com/it/netmedia-serial-lcd-display-2x16-blue.html

And this is a SoftwareSerial child class that implements some of LiquidCrystal methods using the netmedia commands.

It's not finished yet, but I hope it can be useful.

Code: [Select]

class NetmediaSerialLCD : public SoftwareSerial {
public:
    NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(rxPin, txPin) {
    };
   
    void setBacklight(uint8_t brightnessLevel) {
        this->write(20);
        this->write(brightnessLevel);
    };
   
    void clear() {
        this->write(12);
    };
   
    void setCursor(uint8_t column, uint8_t row) {
        this->write(17);
        this->write(row);
        this->write(column);
    };
   
    void createChar(uint8_t location, uint8_t* charmap) {
        this->write(18);
       
        location &= 0x7; // we only have 8 locations 0-7
        location = 64 + (location << 3);
        this->write(location);
        for (uint8_t i = 0; i < 7; i++) {
            this->write(charmap[i]);
        }
    };
};

robtillaart


A serial LCD should only use a TX pin and no RX pin

Does this constructor work?
Code: [Select]

NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(-1, txPin) {
    };

if so you saved an IO pin ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Code: [Select]
        this->write(17);
        this->write(row);
        this->write(column);

In the absence of a specific instance, this is implied. Why do you feel the need to explicitly use this->?

I'm not saying it's wrong. I'm asking why. The only time I use this-> is when a class field has the same name as a local variable (typically a method argument).

tuxduino



A serial LCD should only use a TX pin and no RX pin

Does this constructor work?
Code: [Select]

NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(-1, txPin) {
    };

if so you saved an IO pin ...


I have looked at SoftwareSerial source, and didn't see any test to skip pin initialization in case it has a "special" value. I've put in my todo list the task of looking closer to SS code and see if I can patch it to _actually_ save a pin.
Another solution could be to shamelessly copy the tx code from SoftwareSerial and put it into a new "tx-only" SoftwareSerial class.

tuxduino


Code: [Select]
        this->write(17);
        this->write(row);
        this->write(column);

In the absence of a specific instance, this is implied. Why do you feel the need to explicitly use this->?

I'm not saying it's wrong. I'm asking why. The only time I use this-> is when a class field has the same name as a local variable (typically a method argument).


It just looked clearer to me when I wrote it. Since it's implied, it becomes just a matter of taste IMHO.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy