name changes in a do loop
ftech
Posts: 8
I am having a·problem with space!
I therfore would like to change·a "name"·an make it·"variable name"·in a do loop
ie·as in·below I am using·in Chris data logger program for the data logger and I would like to change "header" in the below code to a number of different names. so i could do something like·where button one being prees in other parts of program would GOTO button1
CHRIS CODE
READ·"VAR NAME" + counter, ioByte······ ' Get Next Byte From EEPROM·
I WOULD LIKE TO DO SOMTHING LIKE THIS
button1:
·"VAR NAME"= header1.
GOSUB·· dataread
button2:
"VAR NAME"= header2.......·· etc NEED 4 NAME CHANGES
GOSUB·· dataread
dataread:
DO
TOGGLE LEDA························ ' Blink Red LED
READ·"VAR NAME" + counter, ioByte······ ' Get Next Byte From EEPROM·
....all othere lines code as in data logger program
LOOP
question is i guess
How can i make header be a variable and therfore changed to Header1 or Header2 Header3 etc
Reason being I need to same similar do loops in getting data from EEPROM and writen to logger and not enough room to double / tripple·up on similar actions
I tried searching fourm do loops variables but didnt find answer
Thanks for any ideas or what to type to search for answers
Cheers
I therfore would like to change·a "name"·an make it·"variable name"·in a do loop
ie·as in·below I am using·in Chris data logger program for the data logger and I would like to change "header" in the below code to a number of different names. so i could do something like·where button one being prees in other parts of program would GOTO button1
CHRIS CODE
READ·"VAR NAME" + counter, ioByte······ ' Get Next Byte From EEPROM·
I WOULD LIKE TO DO SOMTHING LIKE THIS
button1:
·"VAR NAME"= header1.
GOSUB·· dataread
button2:
"VAR NAME"= header2.......·· etc NEED 4 NAME CHANGES
GOSUB·· dataread
dataread:
DO
TOGGLE LEDA························ ' Blink Red LED
READ·"VAR NAME" + counter, ioByte······ ' Get Next Byte From EEPROM·
....all othere lines code as in data logger program
LOOP
question is i guess
How can i make header be a variable and therfore changed to Header1 or Header2 Header3 etc
Reason being I need to same similar do loops in getting data from EEPROM and writen to logger and not enough room to double / tripple·up on similar actions
I tried searching fourm do loops variables but didnt find answer
Thanks for any ideas or what to type to search for answers
Cheers
Comments
You be better off using "alias" in naming your variables. Of course you will need to keep track of their usage carefully. Program with aliases is harder to debug.
Isn’t frustrating when you are short just few locations?
Maybe you should post you program to get the forum to take a look if there is a room for improvement.
Sometimes you do not see the obvious and someone else will.
Yeah program is not at a stage to post.. its a work in progress and in idea form at the moment... think I maybe asking the wrong question or not understanding answer!
The variable is NOT to be a number it is a NAME!
The RESULT from Header = Robert cant result in Header = 4... ie be a number as it is using a counter to count along the bits of data ie
Header + counter , ioByte
I want to change Header to header2 or Robert, Paul etc…even just a G or H so in each loop the program will go to next bit of data at Robert, or G or Paul for each loop till counter makes ioByte 255
If header becomes a number then ioByte will jump to that spot missing data! ie
instead of
robert + counter, ioByte.....= robert 3,3
if
Robert = 4 it will be
4+counter,iobyte ... = 4+3,3
Or am I missing something and having the 4 will not create a math problem? I not great at this stuff
cheers
cheers
I am not past this problem as would like to simplify but now having problem with renaming file which worked before and I have not change it… well hadn’t at that time now I changing it but its right …rrr
There might be a UFO sighting shortly as the unit fly’s over air space when thrown out my window
Header VAR Byte
Peter CON 120
Paul CON 100
Mary CON 130
....
Header = Peter
GOSUB XX
.....
Header = Paul
GOSUB XX
...
.XX:
READ Header + x , Result
RETURN
Location Location is a variable/constant/expression* (0 - 255 on BS1, 0 - 2047 on all other BASIC Stamps) that specifies the EEPROM address to read from.
Post Edited (vaclav_sal) : 9/27/2009 4:33:57 AM GMT
Hopefully I can now sort at least that part out and get it running
cheers
I have searched, I read, I asked my brother but i cant do it... could someone draw me a idiot map please to solve this:
headers data "xxxxxxxxx", 34, xxxxxxx, 0
data "xxxxx,34,xxxxxxxx,0
data "xxxxx", 0, 255
headera data "bbbbbbbb", 34, "bbbbbbbbbb"
data "bbbbbbbbb", 0
data "bbbbbb", 0, 255
headert data "ccccccccccccccccccccccccccccccccccccccccc"
data "ccccccccccccccccccccccccccccccccccccccccc', 34, "ccccccccccccccccccccccccccccccccccccccccc"0, 255
headerf data "ddddddddddddddddddddddddd',0
data "ddddddddddddddddddddddddd, 34, "dddddddddddddddddddddddddddddddddddddddddddd",0
data "ddddddd" 0, 255
Write_Headers:
poss = 0............................ I need this 0 to change to something that the data in EEPROM can be found
GOSUB headerwrite
RETURN
Write_Headera:
poss = 341..........................I need this 341/or headera location to change to something that the data in EEPROM can be found in same do loop below
GOSUB headerwrite
RETURN
Write_Headerc:
RETURN
poss = 384.......................... again this changes in do loop below so do loop write data at headerc
GOSUB headerwrite
RETURN
Write_Headert:
poss = 84
GOSUB headerwrite
RETURN
Write_Headerf:
poss = 433
GOSUB headerwrite
RETURN
headerwrite:
counter = 0
DO
TOGGLE LEDA ' Blink Red LED
READ poss + counter, ioByte ' Get Next Byte From EEPROM
IF ioByte = 0 THEN ' Replace 0 Bytes w/CRLF
SEROUT TX\CTS, Baud, [noparse][[/noparse]$08, $20, $00, $00, $00, $02, $0D,
$0D, $0A, $0D]
ELSEIF ioByte = 255 THEN ' End Of Data Block
EXIT
ELSE
SEROUT TX\CTS, Baud, [noparse][[/noparse]$08, $20, $00, $00, $00, $01, $0D,
ioByte, $0D]
ENDIF
counter = counter + 1 ' Increment Pointer
GOSUB Get_Data ' Purge Receive Buffer
LOOP
RETURN
In above in desperation I tried counting the bytes and using them as a number location to the data as I think has been pointed out in above answers?... I used NO header pointers in that attempt, just data no pointers as in headers headera etc... it writes first lot of data but thats it... the data should I get it working will be words and address etc not just number strings. That part I understand how to do as used Chris's Parallax logger program to understand it. If I place MY header pointer in the loop it will write that data!
My problem is I have the need to go to many Data pointer locations and it takes up to much space to do each pointer do loop seperate and doesnt seem right to do it that way either.
I am sorry I cant explain it better! I just would like to know how to make the above "poss" a variable pointer location to data so writes data at differen start points! (note I am same file different order of data written and or file open and closed ... ie open file xxx bbb cccc ddddd xxx cccc ddddd xxxx ccccc bbbbbbb cccccc dddddd xxxxxxxx xxxxxxx ddddddd ccccccc close file open new file new order of data close file.
thank you for you time effor and understanding as I am sure its as frustrating for you to explain as it is for me to try and understand.. also sorry for any spelling or grammer I not any good at it...
cheers
Start off by describing why you want to do what you're doing, what data is coming into the Stamp and what data is going out and why. You've talked about creating a datalogger. What kind of data are you logging? What's its format? How often is it coming in? Where will it go eventually? What's connected to the Stamp?
Data is going out to logger if one of 4 pins on stamp go high from a external trigger/switch, maybe more if posible.
These are input Pins on stamp BS2, lets call these pins 1, 2, 3, 4, that are triggerd by a switch logic hi or low
start:
(1) program will open a file on data logger
(2) run a constant loop checking these pins.
(3) If no pins high it will log a data stream xxxxxxx and keep looping and logging input data xxxxxxx. This a chaging input of numbers generated and time basically but other numbers too... this part works fine from external source and if done in one section works on stamp no probs.
(4) while looping if one of the pins are triggered it will stop looping write that that has happened from eeprom data, ie pin 1 triggered then go write some other fixed data from eeprom in an order and close file from eeprom data. Does this by going to the told eeprom poiner loctations... ie headera headerc footer
(5) new file will open and repeate but may or may not be same pin same data order ie pin 4 pin 2 pin 4 pin 1 close file
sounds simple enough ;o) modifying the parallax logger file for gps I can cut and shut program to make it work, but not enough room to double up on do loops etc.
So to go to more eeprom data loctation points as in say header A B C D E F G and Footer
"A" being pin 1
"B" being pin 2 etc
"E" data point related to action ie pin one triggered its data written followed by some common data to both thats stored at point "E"
footer written close file
If I could just swap in below Name for headera headerc footer the program would work... ie
pin 1 = 1 then
name = headera
gosub write_data
pin 2 = 1 then
name = headerc................. note that headera, footer or headerc are data location names/points/loctation whatever the correct term is
gosub write_data
Write_data
READ name + counter, ioByte ' Get Next Byte From EEPROM
if I have to use numbers and count the Bytes to use as start point for data strings who do i do this1 i have seen and tried to use the map on the complier but couldnt work out chart and if you use 1D0 as a loctaion it thinks its a name and want it identified.
yes programming is over my head though this seems feasable and i am using a Stamp as Machine code or PIC code I cant write so this is only chance I have of maybe getting some logging of data from my R&D development project going.
cheers
and thank you
headera DATA "This is text",0
headerb DATA "Other text",0
headerc DATA "Still more",0
You'd output this as follows:
name = headera
GOSUB write_data
name = headerb
GOSUB write_data
name = headerc
GOSUB write_data
Your write routine would look like:
write_data:
READ name,ioByte
name = name + 1
IF ioByte = 0 THEN RETURN
SEROUT <pin>,<Baud>,[noparse][[/noparse]ioByte]
GOTO write_data
headerb DATA "Other text",0
headerc DATA "Still more",0
You'd output this as follows:
name = headera
GOSUB write_data
name = headerb
GOSUB write_data
name = headerc
GOSUB write_data
Your write routine would look like:
write_data:
READ name,ioByte
name = name + 1
IF ioByte = 0 THEN RETURN
SEROUT <pin>,<Baud>,[noparse][[/noparse]ioByte]
GOTO write_data
*** I believe you could have a 'write' routine that looked like this:
write_data:
· SEROUT <pin>, <baudmode>, [noparse][[/noparse]STR Name]
· return
·
Read the manual's description of STR in the chapter on SEROUT. That only works if the string is stored in a byte array in the (very limited) variable space.