Shop OBEX P1 Docs P2 Docs Learn Events
Shorten this code? — Parallax Forums

Shorten this code?

FformulaAFformulaA Posts: 9
edited 2007-11-30 01:54 in BASIC Stamp
Got any ideas how to shorten this code?

GOSUB Screen_Year               'Setup Screen

DO
'Goes through a loop for keys
LOOP

GOSUB Screen_Month               'Setup Screen

DO
'Goes through a loop for keys
LOOP

'-----------[noparse][[/noparse]Subs(yummy)]--------------------------------

Screen_Year:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls]            ' Clear The LCD Display
PAUSE 5
SEROUT LCD, Baud, [noparse][[/noparse]"Enter year, i.e.     5 = 2005; 99 = 2099Year:", DEC info2 ]', LcdCR]
RETURN

Screen_Month:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls]            ' Clear The LCD Display
PAUSE 5
SEROUT LCD, Baud, [noparse][[/noparse]"Enter month, i.e.   1=Jan; 11=November  Month:", DEC info2 ]', LcdCR]
RETURN

Screen_Date:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls]            ' Clear The LCD Display
PAUSE 5
SEROUT LCD, Baud, [noparse][[/noparse]"Enter current date,                     Date:", DEC info2 ]', LcdCR]
RETURN

Screen_Day:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls]            ' Clear The LCD Display
PAUSE 5
SEROUT LCD, Baud, [noparse][[/noparse]"Enter day of week,  i.e. 1=Sun 7=Sat    Day:", DEC info2 ]', LcdCR]
RETURN






Would like to use 1 SEROUT command for the strings of data. I tried storing the strings with the data variable. Sort of like this:


'-----------------Variables---------------------------------------------------------
scrn_Year             DATA    "Enter year, i.e.     5 = 2005; 99 = 2099Year:",0
scrn_Month           DATA    "Enter month, i.e.   1=Jan; 11=November  Month:",0
scrn_Msg              VAR      WORD
'--------------------------------------------------------------------------------------

scrn_msg = scrn_Year

GOSUB Set_Screen

DO
'loop through till keys have been entered.
LOOP


Set_Screen:
SEROUT LCD, Baud, [noparse][[/noparse]LcdCls]            ' Clear The LCD Display
PAUSE 5
SEROUT LCD, Baud, [noparse][[/noparse]STR scrn_msg, 13 ]







But all it did was put all sorts of characters on the LCD in a random fashion. Any input would be great. The code as is works, just like to save some space if I can. yeah.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-28 23:19
    Changing from having long strings of text in SEROUT statements to having long strings of text in DATA statements won't save that much. The problem is that the long strings of text take a lot of memory no matter where in the EEPROM you put them. If you must have long strings of text, you should consider changing to another Stamp model that has several "slots" of program memory and you could move all the messaging into some other slot. If you use a BS2p/pe/px, the coding would be the easiest.
  • FformulaAFformulaA Posts: 9
    edited 2007-11-28 23:25
    Actually I'm using a BS2e which has multiple slots. I just thought I could save some space in this slot by removing all the SEROUT commands and replacing them with just one. I haven't programmed these in awhile and thought that I may not be thinking about this the right way. But right, wherever I put the strings they will be there in the memory somewhere, taking up the same amount of space.
  • Rory StormRory Storm Banned Posts: 16
    edited 2007-11-29 01:19
    You are using

    SEROUT·LCD,·Baud,·[noparse][[/noparse]LcdCls]············'·Clear·The·LCD·Display
    PAUSE·5

    in several places.· That bit could be made into a subroutine of its own for a small economy.
  • FformulaAFformulaA Posts: 9
    edited 2007-11-29 02:59
    Sweet peas. Didn't even notice that! I'll give it a try [noparse]:)[/noparse]
  • GICU812GICU812 Posts: 289
    edited 2007-11-29 14:09
    Note: Did you add the second part just now, or did I completely skip over it when I read your post? At any rate, I allready typed all the below up, even though its just another way of doing what you did, im leaving it tongue.gif





    Definitly compress the clearing, also, can you store the text portion then call it? You could do a "select case". That would elimante all the serout commands

    I just dont know how to actually transfer the text, as text = "this is some text" wont work, will it?

    Hopefully someone more knowlegeable than myself can clear that part up, otherwise this wont work at all.

    'do your programming here
    'yaddda yaddda
    'Display Enter year promt
    x=1
    GOSUB printer

    'more programming
    'Display enter date
    x=3
    GOSUB printer




    printer:
    SEROUT LCD, Baud, [noparse][[/noparse]LcdCls] ' Clear The LCD Display
    PAUSE 5
    SELECT x
    CASE 1 text = "Enter year, i.e. 5 = 2005; 99 = 2099Year:"
    CASE 2 text = "Enter month, i.e. 1=Jan; 11=November Month:"
    CASE 3 text = "Enter current date, Date:"
    CASE 4 text = "Enter day of week, i.e. 1=Sun 7=Sat Day:"
    END SELECT

    SEROUT LCD, Baud, [noparse][[/noparse]text, DEC info2]', LcdCR

    RETURN



    Another much simpler option would be to shorten the examples, or better yet, have them enter it in a DD/MM/YYYY format.

    I dont recall how off hand, at least not in PBasic, but I believe you can trim leading\trailing numbers to just select the parts you want.

    Post Edited (GICU812) : 11/29/2007 2:14:25 PM GMT
  • FformulaAFformulaA Posts: 9
    edited 2007-11-30 01:54
    Yeah, it was there all along. I will give your idea a go. Thanks for all the ideas guys!
Sign In or Register to comment.