Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

AxelG's Content

There have been 52 items by AxelG (Search limited from 29-April 23)


By content type

See this member's


Sort by                Order  

#46201 4X20 LCD display with I2C Interface

Posted by AxelG on 25 February 2013 - 03:54 AM in Project Showcase

Thanks for the great project! I was wondering if you would be able to post you display class so I can see how you implement the LCD sreen? Thanks again!

Sorry it has taken some time to respond, I have been working on another project and just now getting back here.  I moved the MakeTextBlock() method into a display class that is quite specific to my project and may not make much sense posted as a helper-class.

 

Essentially this method uses a four element array of strings, one fore each line of the display.  This way it is easy to handle wrapping text on the screen; pass in a large string and the string gets broken into four smaller strings broken at the space character (and optionally centered on each line)

 

I can look at breaking out a more generic class if you are still interested; but it really isn't anything that special...




#46286 4X20 LCD display with I2C Interface

Posted by AxelG on 27 February 2013 - 02:28 AM in Project Showcase

I looked at my code again, and it is not what you are looking to do, but here are the display methods so you can see what I did:

 

        /// <summary>        /// Writes a string array to the device.  Truncates strings to the number of columns allowed,         ///  or wraps if enough room.        /// </summary>        /// <param name="data">string array with each element mapped to a line on the LCD.  Will         ///   truncate if too many are sent</param>        /// <param name="format">C = center each line</param>        private void write(string[] data, char format = ' ')        {            int NumRows = data.Length;            if (NumRows > _rows) NumRows = _rows;            //base.clear();            //truncate the strings, and center if needed            lock (LCDLock)            {                for (int i = 0; i < NumRows; i++)                {                    if (data[i].Length > _cols) data[i] = data[i].Substring(0, _cols);                    if(data[i].Length != 0) write(data[i], 0, (byte)i, format);                }            }        }        /// <summary>        /// Takes in a string, and breaks it up into four strings suitable for the display        /// </summary>        /// <param name="value">String to be converted</param>        /// <returns>string array containing one element for each row on the display</returns>        public string[] MakeTextBlock(string value)        {            int LastSpace = 0;            string[] TextBlock = new string[_rows];            for (int i = 0; i < _rows; i++) TextBlock[i] = "";            for (int pass = 0; pass < _rows; pass++)            {                int SegLen = _cols;                if (value.Length < LastSpace + _cols) SegLen = value.Length - LastSpace;                int ThisSpace = 0;                string part = value.Substring(LastSpace, SegLen);                ThisSpace = part.Length;                if (part.Length >= _cols)                {                    for (int i = 0; i < part.Length; i++) if (part[i] == ' ') ThisSpace = i;                }                TextBlock[pass] = part.Substring(0, ThisSpace);                LastSpace += ThisSpace + 1;                if (LastSpace >= value.Length) break;            }            return TextBlock;        }        /// <summary>        /// Write the string at a specific location, with a specific formatting        /// </summary>        /// <param name="value">Value to display</param>        /// <param name="col">Starting column </param>        /// <param name="row">Row to display</param>        /// <param name="format">C = Centered on the row</param>        private void write(string value, byte col, byte row, char format = 'c')        {            string NewString = "";            if ((format == 'c' || format == 'C') && value.Length < _cols && col == 0)            {                for (int space = 0; space < (_cols - value.Length) / 2; space++) NewString += " ";                NewString = NewString + value;            }            else NewString = value;            lock (LCDLock)            {                base.setCursor(col, row);                write(NewString);                //if (row == TEMPROW && NewString.Trim().Length != 0) LastTempLine = DateTime.Now;            }        }        /// <summary>        /// Send string to the current cursor position        /// If the string is longer than number of columns, the string will be broken        ///   up into parts and written across multiple lines.        /// </summary>        /// <param name="value">string value to display</param>        private void write(string value)        {            if (value.Length > _cols)            {                write(MakeTextBlock(value), 'c');            }            else            {                byte[] Buffer = Tools.Chars2Bytes(value.ToCharArray());                lock (LCDLock)                    base.write(Buffer);            }        }




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.