Shop OBEX P1 Docs P2 Docs Learn Events
LCD Code in Parallax book Smart Sensors & Applications Version 1.0 — Parallax Forums

LCD Code in Parallax book Smart Sensors & Applications Version 1.0

I finally got a Parallax LCD, after getting my 2004 Scott Edwards LCD working. This means I can start working through the Parallax book, Smart Sensors & Applications Version 1.0, with my Parallax LCD. Everything worked until I got to page 15 in the book. On page 15 it said this:
"Here's a code block that will make the text "Line 1" slide across the display's bottom line, from right to left." I entered my own first line of code to turn the LCD on, and clear the screen.
' {$STAMP BS2}
' {$PBASIC 2.5}
SEROUT 14, 84, [22,12] 'My own line of code to turn the LCD on and clear the screen.

FOR index = 9 TO 0 'Start of code out of book, page 15

SEROUT 14, 84, [148 + index, "Line 1 "]
PAUSE 100
NEXT
What happens when I try to run this code is that an error pops up and says "Expected a variable". The word "index' is darkened in the line FOR index = 9 TO 0. What do I need to put in the code to make it work? Thanks.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2016-08-08 14:58
    You have not yet declared index as a variable at the beginning of your program.

    Variables must be declared before being used so that the interpreter knows what size the variable is and allocates the proper space for it.
  • Yes, I understand. I went back and declared index as a VAR and assigned a Byte. The program ran on the LCD as it should. Thanks Chris. I am green and stupid at coding--hope to get better---working hard.
  • Keith,

    That code block on page 15 is used in the program that follows.
    Most languages, as Chris mentions, need variables declared BEFORE they are used.
    Because index goes from 0 to 9, it would be a NIBble type variable since a Nibble can go from 0 to 15.
    If you look at the program that starts on page 15, you will see that index is declared as a NIB.

    BTW, unlike some of the other Stamp In Class books, the code for this one is downloadable and ready to run.
    https://www.parallax.com/downloads/smart-sensors-code-and-spreadsheet

Sign In or Register to comment.