lcd scrolling text and infinite loop setup

Two questions popped into my head this morning:

does void setup() act like void loop() if one places an infinite loop case statement into the setup function?

and does anyone know of a scrolling text library/example sketch for lcd’s? I made one a few days back, it scrolled the word “hello” from left to right, but the code was terribly dirty, in the sense that it was a for loop which moved the word over one “space” each second… this was terribly static because you had to change a number of parameters, such as starting cursor position, when switching words…

does anyone have a way of scrolling text using very neat, clean code?

In plain old c which only uses int main(void)

The setup and loop equals

int main(void)
{
<---------- the setup function

while(1 = 1)
{

<---------- The endless loop function

}
}

  1. yes if you put an infinite loop inside the setup function it would never exit the loop and in a sense be like the void loop method.

  2. I use the sparkfun serial lcd and the code is quite simple to make it loop but it’s part of the sparkfunSerLcd library. Not familiar with anything else.

Might give it a download and pick through the code for some ideas though.

thanks, I’ll take a look at that…

and does anyone know of a scrolling text library/example sketch for lcd’s?

Funny (and timely), I just finished writing a ticker tape type program for use with a 16x2 character LCD:

/*
TickerTape.cpp, based off of LCD_example from
http://www.hacktronics.com/Tutorials/arduino-character-lcd-tutorial.html
*/

#include <LiquidCrystal.h>

const int BACK_LIGHT = 13; // Pin 13 will control the backlight
const char* MESSAGE = "Example 2: Hello there, world. ";
const int MESSAGE_LENGTH = 31;
const int DISPLAY_WIDTH = 16;

// Connections:
// RS (LCD pin 4) to Arduino pin 12
// RW (LCD pin 5) to Arduino pin 11
// Enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal g_lcd(12, 11, 10, 5, 4, 3, 2);
int g_nPosition = 0;

void setup()
{
pinMode(BACK_LIGHT, OUTPUT);
digitalWrite(BACK_LIGHT, HIGH); // Turn backlight on. Replace ‘HIGH’ with ‘LOW’ to turn it off.
g_lcd.clear(); // Start with a blank screen
Serial.begin(9600);
}

void loop()
{
int i;
if(g_nPosition < MESSAGE_LENGTH - DISPLAY_WIDTH)
{
for(i=0; i<DISPLAY_WIDTH; i++)
{
g_lcd.setCursor(i, 0);
g_lcd.print(MESSAGE[g_nPosition + i]);
}
}
else
{
int nChars = MESSAGE_LENGTH - g_nPosition;
for(i=0; i<nChars; i++)
{
g_lcd.setCursor(i, 0);
g_lcd.print(MESSAGE[g_nPosition + i]);
}

for(i=0; i<(DISPLAY_WIDTH - nChars); i++)
{
g_lcd.setCursor(nChars + i, 0);
g_lcd.print(MESSAGE*);*

  • }*
  • }*
  • g_nPosition++;*
  • if(g_nPosition >= MESSAGE_LENGTH)*
  • {*
  • g_nPosition = 0;*
  • }*
  • delay(500);*
    }
    -Jeff

// DF Robot LCD Shield w/1602B
LiquidCrystal g_lcd(8, 11, 9, 4, 5, 6, 7);