Step 6: More Efficient Sketch

A few days after i had posted my code on the Arduino forums back in early 2010, Mark S adapted it to be table driven. Since it is table driven it uses no RAM. While it complicates the sketch a bit it is a more efficient way of setting up the large font and goes a long way to making the fonts usable. I don't fully understand it myself but i'm including the code here in text form only.

This was made back in 2008 on IDE 0.8. Things have changed a bit since then so the sketch might not compile. I had to make some adjustments to my original sketch before i could post it here since the Liquid CrystalLibrary had changed a bit since i last used the sketch. 

Here is a link to the thread in the Arduino Forum Archives where i first demonstrated this custom font. There you can read about the evolution that took place in refining the font and the sketch.
<p>Great Work!</p><p>Naksh</p><p>www.nrdcentre.com</p>
<p>Hey, great instructable. When I first saw the 2x16 display had 8 programmable characters, I was hoping large fonts or some graphics would be possible, but given the few characters, and only two lines to work with, I just assumed a big font would be impossible. </p><p>But wow, you did an amazing job making it look nice with minimal characters. Kudos. It was inspiring for me to contribute back some improvements. Very creative an minimalistic use of the corners and edge pieces.</p><p>While your letters looked great, in all honesty, your novice (but working!) C code truly made my eyeballs bleed. (Not a snob; I used to do mainframe C compliler language compliance testing, and have worked on Unix utilities for years; so I'm a bit fussy about my C. Code efficiency and compactness is key with me, and are right at home in the Arduino world :) Rather than complain, I'll contribute :)</p><p><strong>Updated Version</strong></p><p>I've reworked your code to add the following:</p><p>- Single nested table for programmable char definitions, rather than 8 global vars<br>- Character design moved into tables, rather than many lines of code. This cuts<br>the sketch size by about half. and makes editing/adding characters easier.<br>- Put character table as a ' '-'_' (ascii 20-5F) table, so other ascii characters could be filled in.<br>- I added Space, period to get character additions rolling. But I got bored, and did a first crack at all the missing characters 0x20-0x5F (mostly punctuation). (A crazy Friday night here, I tell ya, a bit bleary-eyed near the end.) Some of the chars are pretty rough, it'd be great if Michael and/or others could improve upon them.<br>- Used space (hex 20) instead of FE (254 dec) as a blank character, more portable.<br>- Overwrites empty spots in a letter with a space, to help clear overwritten chars.<br>- Added writeString() and writeChar() function. These handle wrapping around the 40-character LCD buffer elegantly for continuous scrolling.<br>- Redid the demo loop, removing global varibables, lists of letters, etc., much simplified and more browseable, IMO.<br>- Call lcd.begin() before programming characters. I would get random dropouts on the prog characters before I did this.</p><p>This should be easier to use, more compact, faster, easier to maintain.</p><p>I'm going to post it to a blog or instructable (with references back here), but wouldn't mind feedback here (specificially from Michael on the glyphs) before finalizing it.</p><p><strong>The sketch</strong></p><p>{{{</p><p>// Based upon the amazing 2-line character set designed by Michael Pilcher<br><br>// Cleaned up for space, efficiency:<br>//<br>// - Single array for programmable characters<br>// - Looped initialization from this table, rather than a series of calls<br>// - Big character composition stored in strings, rather than drawn in functions<br>// One-line per character definition, instead of 11 or so<br>// Makes character tweaking a lot easier<br>// - Characters in an ASCII table, to encourage adding of more characters<br>// - Added the rest of ascii characters 0x20-0x5F (some could use improvement :)<br>// - writeString() function<br>// - Far fewer system calls by writing strings rather than one-byte-per-call<br>// (Note: I changed back to one-byte-per-write, as writing multiple bytes at once<br>// seems to fail to wrap in the LCD's circular display buffer).<br>// - Handles wrapping of LCD circular display buffer :)<br>// - Writes out blank spots in each letter, for cleaner overwriting of previous text<br>// - Uses Space instead of hex 254 blank character; possibly more portable to other displays<br>// - The demo loop is far more elegant (no more x = x + 4, x = x + 4, x = x + 4 :)<br>// - Initialization (begin) called before programming the characters<br>// (Without this, I had inconsistent character programming between runs.)<br><br>// This should run faster, be more stable, provide more characters, take half the space, <br>// and be easier to maintain, than the original.<br>//<br>// Dale Gass<br>// May 10, 2014<br><br>#include &lt;LiquidCrystal.h&gt;<br><br>// Taylor to your pin arrangement<br>// My wiring keeps the 'interruptable' pins 2/3 free for interrupt sue<br>// and pins 10/11 free for SPI communictions/PWM. Plus on the mini Pro,<br>// the six control lines are now sequential along the side of the board,<br>// making wiring easier (using a pin header).<br><br>LiquidCrystal lcd(9, 8, 7, 6, 5, 4);<br><br>/* My circuit:<br> * LCD RS pin to digital pin 9<br> * LCD Enable pin to digital pin 8<br> * LCD D4 pin to digital pin 7<br> * LCD D5 pin to digital pin 6<br> * LCD D6 pin to digital pin 5<br> * LCD D7 pin to digital pin 4<br> * LCD R/W pin to ground<br> * 10K resistor:<br> * ends to +5V and ground - I just grounded pin 3 for full contract<br> * wiper to LCD VO pin (pin 3)<br>*/<br><br>// The standard wiring which prevents int 2/3 and SPI use:<br>// Most common in Arduino LCD samples<br>// LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br><br>// Eight programmable character definitions<br>byte custom[8][8] = {<br>{ B11111,<br> B11111,<br> B11111,<br> B00000,<br> B00000,<br> B00000,<br> B00000,<br> B00000 },<br> <br>{ B11100,<br> B11110,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111 },<br><br>{ B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B01111,<br> B00111 },<br><br>{ B00000,<br> B00000,<br> B00000,<br> B00000,<br> B00000,<br> B11111,<br> B11111,<br> B11111 },<br><br>{ B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11110,<br> B11100 },<br><br>{ B11111,<br> B11111,<br> B11111,<br> B00000,<br> B00000,<br> B00000,<br> B11111,<br> B11111 },<br><br>{ B11111,<br> B00000,<br> B00000,<br> B00000,<br> B00000,<br> B11111,<br> B11111,<br> B11111 },<br><br>{ B00111,<br> B01111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111,<br> B11111 }<br>};<br><br>// Characters, each with top and bottom half strings<br>// \nnn string encoding is octal, so:<br>// \010 = 8 decimal (8th programmable character)<br>// \024 = 20 decimal (space)<br>// \377 = 255 decimal (black square)<br><br>const char *bigChars[][2] = { <br> {&quot;\024\024\024&quot;, &quot;\024\024\024&quot;}, // Space<br> {&quot;\377&quot;, &quot;\007&quot;}, // !<br> {&quot;\005\005&quot;, &quot;\024\024&quot;}, // &quot;<br> {&quot;\004\377\004\377\004&quot;, &quot;\001\377\001\377\001&quot;}, // #<br> {&quot;\010\377\006&quot;, &quot;\007\377\005&quot;}, // $<br> {&quot;\001\024\004\001&quot;, &quot;\004\001\024\004&quot;}, // %<br> {&quot;\010\006\002\024&quot;, &quot;\003\007\002\004&quot;}, // &amp;<br> {&quot;\005&quot;, &quot;\024&quot;}, // '<br> {&quot;\010\001&quot;, &quot;\003\004&quot;}, // (<br> {&quot;\001\002&quot;, &quot;\004\005&quot;}, // )<br> {&quot;\001\004\004\001&quot;, &quot;\004\001\001\004&quot;}, // *<br> {&quot;\004\377\004&quot;, &quot;\001\377\001&quot;}, // +<br> {&quot;\024&quot;, &quot;\005&quot;}, // ,<br> {&quot;\004\004\004&quot;, &quot;\024\024\024&quot;}, // -<br> {&quot;\024&quot;, &quot;\004&quot;}, // .<br> {&quot;\024\024\004\001&quot;, &quot;\004\001\024\024&quot;}, // /<br> {&quot;\010\001\002&quot;, &quot;\003\004\005&quot;}, // 0<br> {&quot;\001\002\024&quot;, &quot;\024\377\024&quot;}, // 1<br> {&quot;\006\006\002&quot;, &quot;\003\007\007&quot;}, // 2<br> {&quot;\006\006\002&quot;, &quot;\007\007\005&quot;}, // 3<br> {&quot;\003\004\002&quot;, &quot;\024\024\377&quot;}, // 4<br> {&quot;\377\006\006&quot;, &quot;\007\007\005&quot;}, // 5<br> {&quot;\010\006\006&quot;, &quot;\003\007\005&quot;}, // 6<br> {&quot;\001\001\002&quot;, &quot;\024\010\024&quot;}, // 7<br> {&quot;\010\006\002&quot;, &quot;\003\007\005&quot;}, // 8<br> {&quot;\010\006\002&quot;, &quot;\024\024\377&quot;}, // 9<br> {&quot;\004&quot;, &quot;\001&quot;}, // :<br> {&quot;\004&quot;, &quot;\005&quot;}, // ;<br> {&quot;\024\004\001&quot;, &quot;\001\001\004&quot;}, // &lt;<br> {&quot;\004\004\004&quot;, &quot;\001\001\001&quot;}, // =<br> {&quot;\001\004\024&quot;, &quot;\004\001\001&quot;}, // &gt;<br> {&quot;\001\006\002&quot;, &quot;\024\007\024&quot;}, // ?<br> {&quot;\010\006\002&quot;, &quot;\003\004\004&quot;}, // @<br> {&quot;\010\006\002&quot;, &quot;\377\024\377&quot;}, // A<br> {&quot;\377\006\005&quot;, &quot;\377\007\002&quot;}, // B<br> {&quot;\010\001\001&quot;, &quot;\003\004\004&quot;}, // C<br> {&quot;\377\001\002&quot;, &quot;\377\004\005&quot;}, // D<br> {&quot;\377\006\006&quot;, &quot;\377\007\007&quot;}, // E<br> {&quot;\377\006\006&quot;, &quot;\377\024\024&quot;}, // F<br> {&quot;\010\001\001&quot;, &quot;\003\004\002&quot;}, // G<br> {&quot;\377\004\377&quot;, &quot;\377\024\377&quot;}, // H<br> {&quot;\001\377\001&quot;, &quot;\004\377\004&quot;}, // I<br> {&quot;\024\024\377&quot;, &quot;\004\004\005&quot;}, // J<br> {&quot;\377\004\005&quot;, &quot;\377\024\002&quot;}, // K<br> {&quot;\377\024\024&quot;, &quot;\377\004\004&quot;}, // L<br> {&quot;\010\003\005\002&quot;, &quot;\377\024\024\377&quot;}, // M<br> {&quot;\010\002\024\377&quot;, &quot;\377\024\003\005&quot;}, // N<br> {&quot;\010\001\002&quot;, &quot;\003\004\005&quot;}, // 0/0<br> {&quot;\377\006\002&quot;, &quot;\377\024\024&quot;}, // P<br> {&quot;\010\001\002\024&quot;, &quot;\003\004\377\004&quot;}, // Q<br> {&quot;\377\006\002&quot;, &quot;\377\024\002&quot;}, // R<br> {&quot;\010\006\006&quot;, &quot;\007\007\005&quot;}, // S<br> {&quot;\001\377\001&quot;, &quot;\024\377\024&quot;}, // T<br> {&quot;\377\024\377&quot;, &quot;\003\004\005&quot;}, // U<br> {&quot;\003\024\024\005&quot;, &quot;\024\002\010\024&quot;}, // V<br> {&quot;\377\024\024\377&quot;, &quot;\003\010\002\005&quot;}, // W<br> {&quot;\003\004\005&quot;, &quot;\010\024\002&quot;}, // X<br> {&quot;\003\004\005&quot;, &quot;\024\377\024&quot;}, // Y<br> {&quot;\001\006\005&quot;, &quot;\010\007\004&quot;}, // Z<br> {&quot;\377\001&quot;, &quot;\377\004&quot;}, // [<br> {&quot;\001\004\024\024&quot;, &quot;\024\024\001\004&quot;}, // Backslash<br> {&quot;\001\377&quot;, &quot;\004\377&quot;}, // ]<br> {&quot;\010\002&quot;, &quot;\024\024&quot;}, // ^<br> {&quot;\024\024\024&quot;, &quot;\004\004\004&quot;}, // _ <br>};<br><br>int writeBigChar(char ch, int x, int y) {<br> const char *(*blocks)[2] = NULL; // Pointer to an array of two strings (character pointers)<br><br> if (ch &lt; ' ' || ch &gt; '_') // If outside our table range, do nothing<br> return 0;<br> <br> blocks = &amp;bigChars[ch-' ']; // Look up the definition<br><br> for (int half = 0; half &lt;=1; half++) {<br> int t = x; // Write out top or bottom string, byte at a time<br> for (const char *cp = (*blocks)[half]; *cp; cp++) {<br> lcd.setCursor(t, y+half); <br> lcd.write(*cp);<br> t = (t+1) % 40; // Circular scroll buffer of 40 characters, loop back at 40<br> }<br> lcd.setCursor(t, y+half);<br> lcd.write(' '); // Make space between letters, in case overwriting<br> }<br> return strlen((*blocks)[0]); // Return char width<br>}<br><br>void writeBigString(char *str, int x, int y) {<br> char c;<br> while ((c = *str++))<br> x += writeBigChar(c, x, y) + 1;<br>}<br> <br>void setup()<br>{<br> lcd.begin(16, 2);<br> for (int i=0; i&lt;8; i++)<br> lcd.createChar(i+1, custom[i]);<br><br> lcd.clear();<br> writeBigString(&quot;TEST&quot;, 0, 0);<br> delay(2000);<br><br> lcd.clear();<br>}<br><br>int x = 16; // Start writing the character just off the display, and scroll it in<br><br>void loop()<br>{<br> char ch;<br><br> for (ch=' '; ch&lt;='_'; ch++) {<br> int w = writeBigChar(ch, x, 0); // Write big character just off the scren<br> for (int j=0; j&lt;w+1; j++) { // Scroll it in<br> lcd.scrollDisplayLeft();<br> delay(400);<br> }<br> x = (x + w + 1) % 40; // Adjust our new X, handling circular buffer wrap<br> }<br>}</p><p>[/code]</p><p>Let me know any changes or suggestions, in particular with the Glyph design, and I'll get this posted in the next few days.</p><p><strong>Pointers</strong></p><p>The C should be pretty straight forward; I use a few slightly advanced C pointer constructs, like &quot;const char *(*p)[2]&quot; (a variable v, which is a pointer, to an array of two pointers to const chars [an array of two string pointers]. There's an art to understanding and creating C pointers like that; think reading from the inside outworks, working from right to left. Hard to explain, but good to understand to be able to do things efficiently.</p><p>const char *(<strong><em>*p</em></strong>)[2] - 'p' is a pointer to...</p><p>const chart *(*p)<strong>[2]</strong> - an array of two...</p><p><em><strong>const char *</strong></em>(*p)[2] = pointers to const chars (i.e. constant strings)</p><p><a href="http://boredzo.org/pointers/" rel="nofollow">This page</a> has a good rundown of C pointer syntax. Required reading if you're doing any level of Arduino programming beyond the basics.</p><p>(If you are tight for space, you could null out {&quot;&quot;, &quot;&quot;} the definintions for characters that you aren't using in your app. Even better, moving those arrays to PROGMEM (putting them in FLASH instead of prescious RAM) would save a lot, too. Unfortunately all the type-casting required to make PROGMEM arrays obfuscates the code too much. I erred on the side of readability.)</p><p>Thanks again for a creative and inspired font design under tough technical restrictions. Very inspiring.</p><p>Open to any questions, feedback, suggestions.</p><p>-dale</p>
<p>Thanks Dale, yours is easier to understand. (at least, for my limited knowledge of C/C++;)</p><p>x2nie</p>
<p>OMG! Thanks!</p><p>Only took 6 years for someone to finally make this useable for most everyone. This deserves to be an instructable. I'd wait for a suitable contest to come along before posting it. Would make for a good entry. </p><p>When i find some time i'll have to dive into this a bit and see what else i can do. May prove rather useful in a couple of projects i have in mind. </p>
very interesting and wery useful this article... I adapted your sketch for LCD with i2c interface and is ok... my adapted sketch is at http://nicuflorica.blogspot.ro/2013/06/caractere-mari-pe-afisaj-de-2-randuri.html
I just found this. Thanks great work. I am trying to build a large font display for an antenna rotor for a friend who can't see the small analogue needle. So I got my display reading my pot input as 0-360 , but how do I get it to display the large fonts?? <br>Thanks again.
Take a look at step 5 again and see the sketch posted there. Most of the code sets up each letter and number as custom calls. Then the void letters set up which characters i want on the screen. The in the void loop we bring it all together using for statements to have the full set of characters scroll across the screen. <br> <br>Any sketch you create will have to call to the correct void custom to bring up the letter or number you want to display. You will need to take the number you want to display and have a translator function that can break 360 down to 3, 6, and 0 each being stored to there own variable. Then make comparisons between the variable and each number. When a match is found call to that custom character and display it. It's also important to have the correct number of cursor spaces between the first column of the first character and the first column of the next character. Characters like the 'M' and 'W' are wider then the rest. <br> <br>Course all of this makes your code much longer and slower. So if you don't want any kind of delay between moving your pot and getting the readout then this may not be the best option for you.
Ok sounds interesting. ANy ideas on how to do that? (You knew I'd ask...LOL) I looked at converting to a String and you can get character/number positions out of it but I don't know how yet.
Think about a math problem that will be able to get rid of the other digits. May have to be a series of equations that will pull it off. Take the variable and subtract 100. If the variable is greater than 100 add 1 to a tracking variable and loop back to subtract 100 again. If the variable is less than 100 store the tracking variable to the variable for displaying the hundreds and move on to doing a similar equation for the tens and ones. By the end of it all you will have a variable for the hundreds, tens, and ones that match the original number and can make calls to the appropriate character to be displayed.<br> <br> There is likely a much simpler way of doing it but that is the first thing to come to mind.<br> <br> Quick code of the hundreds breakdown:<br> <em>int analog = ??? //value read from the pot input<br> int track = 0 //tracking variable<br> int hund = 0 //hundreds place<br> int ten = 0 //tens place<br> int one = 0 //ones place<br> int comp = analog //for storing analog variable after numbers have been subtracted<br> <br> viod breakhund()<br> if comp &gt;100<br> comp = analog-100<br> track++<br> breakhun<br> end<br> <br> if comp &lt; 100<br> hund = track<br> track = 0<br> breakten<br> <br> void breakten()</em><br> <br> <br> Of course&nbsp;punctuation&nbsp;is missing but that should give you an idea. The tens and ones will follow in the same&nbsp;fashion.&nbsp;You can pretty much copy and past the same code just drop a zero each time.&nbsp;
Thanks. I finally got some time and I got it to work as you indicated. (Or very close) so I have it displaying 0-360 like I need. I can't get it to clear the numbers properly, such as when you change from 0 to 1 it still displays bits of the 0 along with the 1. I tried using the lcd.write(&quot; &quot;); but it didn't work, I put it into the spot where it prints characters in the function that is called to print a custom character. I also tried the lcd.clear but it is either too fast to see the characters or too slow and they blink. <br>I thought I'd pick your brain a bit to see if you have an idea. <br>Thanks for your help so far!! <br> <br>Here is the code.. <br> <br>// These constants won't change. They're used to give names <br>// to the pins used: <br>const int analogInPin = A0; // Analog input pin that the potentiometer is attached to <br> <br>int sensorValue = 0; // value read from the pot <br>int outputValue = 0; // value output to the PWM (analog out) <br>//char outputValueChar[5]; <br>int hundreds; <br>int tens; <br>int ones; <br>#include <br>LiquidCrystal lcd(12, 11, 5, 4, 3, 2); <br> <br> <br>// the 8 arrays that form each segment of the custom numbers <br>byte LT[8] = <br>{ <br> B00111, <br> B01111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111 <br>}; <br>byte UB[8] = <br>{ <br> B11111, <br> B11111, <br> B11111, <br> B00000, <br> B00000, <br> B00000, <br> B00000, <br> B00000 <br>}; <br>byte RT[8] = <br>{ <br> B11100, <br> B11110, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111 <br>}; <br>byte LL[8] = <br>{ <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B01111, <br> B00111 <br>}; <br>byte LB[8] = <br>{ <br> B00000, <br> B00000, <br> B00000, <br> B00000, <br> B00000, <br> B11111, <br> B11111, <br> B11111 <br>}; <br>byte LR[8] = <br>{ <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11111, <br> B11110, <br> B11100 <br>}; <br>byte UMB[8] = <br>{ <br> B11111, <br> B11111, <br> B11111, <br> B00000, <br> B00000, <br> B00000, <br> B11111, <br> B11111 <br>}; <br>byte LMB[8] = <br>{ <br> B11111, <br> B00000, <br> B00000, <br> B00000, <br> B00000, <br> B11111, <br> B11111, <br> B11111 <br>}; <br> <br>// loop counter <br>int x = 0; <br> <br> <br>void setup() <br>{ <br> Serial.begin(9600); <br> // assignes each segment a write number <br> lcd.createChar(0,LT); <br> lcd.createChar(1,UB); <br> lcd.createChar(2,RT); <br> lcd.createChar(3,LL); <br> lcd.createChar(4,LB); <br> lcd.createChar(5,LR); <br> lcd.createChar(6,UMB); <br> lcd.createChar(7,LMB); <br> <br> <br> // sets the LCD's rows and colums: <br> lcd.begin(16, 2); <br> <br>} <br> <br>void custom0() <br>{ // uses segments to build the number 0 <br> lcd.setCursor(x, 0); // set cursor to column 0, line 0 (first row) <br> lcd.write((byte)0); // call each segment to create <br> lcd.write(1); // top half of the number <br> lcd.write(2); <br> lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row) <br> lcd.write(3); // call each segment to create <br> lcd.write(4); // bottom half of the number <br> lcd.write(5); <br>} <br> <br>void custom1() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write(1); <br> lcd.write(2); <br> lcd.setCursor(x+1,1); <br> lcd.write(5); <br>} <br> <br>void custom2() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write(6); <br> lcd.write(6); <br> lcd.write(2); <br> lcd.setCursor(x, 1); <br> lcd.write(3); <br> lcd.write(7); <br> lcd.write(7); <br>} <br> <br>void custom3() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write(6); <br> lcd.write(6); <br> lcd.write(2); <br> lcd.setCursor(x, 1); <br> lcd.write(7); <br> lcd.write(7); <br> lcd.write(5); <br>} <br> <br>void custom4() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write(3); <br> lcd.write(4); <br> lcd.write(2); <br> lcd.setCursor(x+2, 1); <br> lcd.write(5); <br>} <br> <br>void custom5() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write((byte)0); <br> lcd.write(6); <br> lcd.write(6); <br> lcd.setCursor(x, 1); <br> lcd.write(7); <br> lcd.write(7); <br> lcd.write(5); <br>} <br> <br>void custom6() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write((byte)0); <br> lcd.write(6); <br> lcd.write(6); <br> lcd.setCursor(x, 1); <br> lcd.write(3); <br> lcd.write(7); <br> lcd.write(5); <br>} <br> <br>void custom7() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write(1); <br> lcd.write(1); <br> lcd.write(2); <br> lcd.setCursor(x+1, 1); <br> lcd.write((byte)0); <br>} <br> <br>void custom8() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write((byte)0); <br> lcd.write(6); <br> lcd.write(2); <br> lcd.setCursor(x, 1); <br> lcd.write(3); <br> lcd.write(7); <br> lcd.write(5); <br>} <br> <br>void custom9() <br>{ <br> lcd.setCursor(x,0); <br> lcd.write((byte)0); <br> lcd.write(6); <br> lcd.write(2); <br> lcd.setCursor(x+2, 1); <br> lcd.write(5); <br>} <br> <br> <br> <br> <br> <br>void loop() { <br> // read the analog in value: <br> sensorValue = analogRead(analogInPin); <br> // map it to the range of the analog out: <br> outputValue = map(sensorValue, 0, 1023, 0, 360); <br> <br> // print the results to the serial monitor: <br> Serial.print(&quot;sensor = &quot; ); <br> Serial.print(sensorValue); <br> Serial.print(&quot;\t output = &quot;); <br> Serial.println(outputValue); <br> <br> String stringOne = String(outputValue); <br> // prints the value of outputValue <br> //Serial.print(&quot;Output value string is &quot;); <br> //Serial.println(stringOne); <br> x=0; <br> hundreds = outputValue /100; <br> //Serial.print(hundreds); <br> delay(500); <br> <br> switch (hundreds) { <br> case 3: <br> custom3(); <br> break; <br> <br> case 2: <br> <br> custom2(); <br> break; <br> <br> case 1: <br> <br> custom1(); <br> break; <br> <br> case 0: <br> <br> custom0(); <br> break; <br> <br> } <br> <br> tens=outputValue /10; <br> tens=tens%10; <br> //Serial.println(tens); <br> <br> switch (tens) { <br> case 9: <br> x=x+3; <br> <br> custom9(); <br> break; <br> <br> case 8: <br> x=x+3; <br> <br> custom8(); <br> break; <br> <br> case 7: <br> x=x+2; <br> <br> custom7(); <br> break; <br> <br> case 6: <br> x=x+3; <br> <br> custom6(); <br> break; <br> <br> case 5: <br> x=x+3; <br> <br> custom5(); <br> break; <br> <br> case 4: <br> x=x+3; <br> <br> custom4(); <br> break; <br> <br> case 3: <br> x=x+3; <br> <br> custom3(); <br> break; <br> <br> case 2: <br> x=x+3; <br> <br> custom2(); <br> break; <br> <br> case 1: <br> x=x+3; <br> <br> custom1(); <br> break; <br> <br> if (outputValue&lt;10) <br> { <br> //case 0: <br> x=x+3; <br> <br> custom0(); <br> break; <br> } <br> <br> case 0: <br> x=x+3; <br> <br> custom0(); <br> break; <br> } <br> <br> ones=outputValue%10; <br> //ones=ones%100; <br> // Serial.println(ones); <br> <br> switch (ones) { <br> case 9: <br> x=x+3; <br> <br> custom9(); <br> break; <br> <br> case 8: <br> x=x+3; <br> <br> custom8(); <br> break; <br> <br> case 7: <br> x=x+3; <br> <br> custom7(); <br> break; <br> <br> case 6: <br> x=x+3; <br> <br> custom6(); <br> break; <br> <br> case 5: <br> x=x+3; <br> <br> custom5(); <br> break; <br> <br> case 4: <br> x=x+3; <br> <br> custom4(); <br> break; <br> <br> case 3: <br> x=x+3; <br> <br> custom3(); <br> break; <br> <br> case 2: <br> x=x+3; <br> <br> custom2(); <br> break; <br> <br> case 1: <br> x=x+3; <br> <br> custom1(); <br> break; <br> <br> case 0: <br> x=x+3; <br> <br> custom0(); <br> break; <br> <br> } <br> /* <br> delay(500); <br> lcd.setCursor(0,1); <br> lcd.print(outputValue); */ <br> //delay(300); <br> //lcd.clear(); <br> <br> //if (outputValue &lt; 100) <br> // { <br> // x=0; <br> // lcd.print(&quot; &quot;); <br> // } <br> <br> // wait 2 milliseconds before the next loop <br> // for the analog-to-digital converter to settle <br> // after the last reading: <br> //delay(10); <br> <br> <br>}
Put the lcd.clear before the set cursor and drop the delay before the set cursor. Keep and play around with the delay after the lcd.print. Should smooth things out for you a bit. <br> <br>There is already a delay with the processing leading up to the print update. So that combined with the delay after the print leaves the display showing strong. Then it get through the processing and clears the screen a millisecond before it prints again causing an imperceptible update.
Looks like I got it, I found a lcd.clear rate that works and no (&quot; &quot;) needed. I also &quot;fixed&quot; what I didn't care for with the 1 digit. So it looks all good now. All with your help though!! Thank you very much!!!
Please, what's the name of that the schematic 3d generator software?
The image above was created with http://fritzing.org
Thanks for the run down man; I have two 16x2 IM161 Microtivity units I'm playing with currently on various Arduino projects.

About This Instructable


61 favorites


Bio: I'm a jack of all trades and a master of none. I like to tweak, mod and improvise whenever possible!
More by mpilchfamily: Universal USB Power Supply Kit FM Bug Detector Kit FM Listening Bug
Add instructable to: