Variable problem
computer guy
Posts: 1,113
Hi there,
I have a long with a string in it "010001".
so
I need to have a if statement check to see if each part of the string is a 1 or a 0.
It is a string to start with because it is read from a txt file on an sd card.
My code reads each line of the txt file and then needs to turn the command "0100001" into something useful.
How would I do this?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Post Edited (computer guy) : 9/4/2008 12:59:20 PM GMT
I have a long with a string in it "010001".
so
[b]long[/b] output_command := "0100001"
I need to have a if statement check to see if each part of the string is a 1 or a 0.
It is a string to start with because it is read from a txt file on an sd card.
My code reads each line of the txt file and then needs to turn the command "0100001" into something useful.
How would I do this?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Post Edited (computer guy) : 9/4/2008 12:59:20 PM GMT
Comments
Have you looked at the Extended Full Duplex Serial object in the Object Exchange. This has
routines that convert input strings into numeric values. It calls Full Duplex Serial, but could
be modified to call the SD card routines instead. In any event, it will show you how to do
numeric string to number conversions. It has a decimal conversion routine, but I don't think
it has a binary number conversion routine. It's just a simple matter of changing a value of 10
to a value of 2 to handle binary numbers.
Post Edited (Mike Green) : 9/4/2008 1:07:22 PM GMT
That is the code I have.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Where exactly can I find the Extended FDS object? I have searched the forums, web and obex however cannot find it anywhere.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Here's the link: obex.parallax.com/objects/31/
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
This input:
But have this output:
Can someone please take a quick look at my code and see what needs to be done to get this to work.
I need both output_time and output_command as a number but am just trying to get output_time to work at the moment.
The other should be easy.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
if i take a QUICK look at your code i can't find the place where the conversion is done
taking a middlelong look at it i see that the method todec still looks for DECIMAL values instead for BINARY values
could you please comment almost each line what you INTEND to do
to me it seems like you have still lack of understanding what longs and pointers to strings are and how to use pointers and strings
f.e. the variable output_time is defined as a long
this means it can contain FOUR bytes (=32bits)
I don't know the fomat functions in detail but one thing is for sure:
there has to place reserved in memory to store the strings in it
if the command fmt.bscanf(t,0,string("%s R"),@output_time)
should store the string at adress of output_time and the string is longer than 4 bytes
it will override the content of the following long output_command !!
inside a string every character needs a byte=8bits. A string of 10 characters needs 10 bytes of memory and you have to reserve it
so i guess one thing to is to define bytearrays where the characters of the strings find place to be stored
the other thing is to change the method ToDec to a NEW method ToBinary
take a look at wikipedia how binary numbers work and then you can program the method yourself
best regards
Stefan
Changing
TO
Has solved the problem of the time and command becoming over written.
However I am sure this uses up excess memory.
This is the function.
I have no idea how todec works as its not my code and not commented at all.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Any ideas?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
and it will return the value 32736327. The string has to be terminated
with some non-digit byte (like the normal zero byte that ends a string).
If the string starts with a non-digit byte, the value zero will be returned.
It still only returns a weird number like 6284.
I will upload my code (commented) when I get home this afternoon.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
This will display the address of output_time, not the value of it. You want:
"term.dec(output_time)"
Now I just need to work out how to analyse each individual value of the number.
I am still learning about bytes, arrays and such.
I would have thought that output_command[noparse][[/noparse] 0] would have given me the first number in output_command and output_command[noparse][[/noparse] 1] would have given me the second.
But it still gives me the entire number.
Also how do I stop the decimal conversion code from truncating the 0's at the start of output_command.
Basically
means that buttons 1 and 6 are pressed.
But the conversion code gets
and returns
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
oh i have a lot thoughts
first is "the members of the forum are willing to help. But there has to come something more from you."
second is "i would like to aks you if you had understand the following line of code"
[noparse][[/noparse]code]
result := result * 10 + (temp - "0")
[noparse][[/noparse]\code]
do you UNDERSTAND what happens here ?
simple answer "yes" or "no"
complete answer: description in your own words what it does
another problem I have:
it is very hard to imagine what you have CODED without seeing your code
nothing is clear
did you use the method that Mike posted above ?
did you use the "old" ToDec-method from your program more above?
everything gets clear if you add comments to your code in that lines where you think the problem isl
an then
please, please, please, please post your COMPLETE code as an attachment
another way could be a test-program just containing the interesting part but still as a COMPLETE program
NO CODE-SNIPPETS !
and if you add an example of what you "put in" and what "comes out" it will become much easier to analyse the whole thing
did you try to debug your code by sending the values of every variable engaged in the conversion to a terminalsoftware like PST.EXE ?
another thing ASCII-code characters have values between 0 and 255 these values fit in one BYTE
define output_time output_comman
as BYTE-arrays NOT as LONG-arrays
best regards
Stefan
No I dont understand the line
I used the code that Mike posted above.
I will finish commenting my code and upload it.
The values are read from an SD card. The output is displayed using the TV text driver.
output_time and output_command have to be a long array as the code that splits the string will only accept a long array.
Thank you for your help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
this line above is from the code that mike posted and that you are using.
i think the array should be a byte-array because
the PUB bscanf(str,si,fmt,arg): index | width,bi,sign,p,skip,sorg
uses commands "byte[noparse][[/noparse]str]" all the time
parameters have to be longs and the parameter "str" of PUB bscanf has to be a long too
But parameter "str" is the POINTER to the BYTE-Array containing the string and NOT the array itself
if the string is "ABC" which is in ASCII-code A=65, B=66, C=67
the byte-array contains
first byte 65
second byte 66
third byte 67
the POINTER contains the ADRESS WHERE the values 65 66 67 are stored
Let's say the base-adress of the string-pointer str is 1000
if you increment the value of str by one and use it with byte[noparse][[/noparse]str] you are accessing
RAM-Byte 1001
if you use it with long[noparse][[/noparse]str] you access RAM-Byte 1005
or other way round if you have stored the characters of your string in a LONG-array
Let's say the string is "ABC" which is in ASCII-code A=65, B=66, C=67
the RAM-bytes contain the following
byte 1000: 65
byte 1001: 0
byte 1002: 0
byte 1003: 0
byte 1004: 66
byte 1005: 0
byte 1006: 0
byte 1007: 0
byte 1008: 67
byte 1009: 0
byte 1010: 0
byte 1011: 0
now the PUB bscanf(str,si,fmt,arg): index | width,bi,sign,p,skip,sorg
accesses the string by byte[noparse][[/noparse]str]
with the first character this is working
then str which contains value 1000 is incremented by one
new value 1001
byte[noparse][[/noparse]str]=byte[noparse][[/noparse]1001] gets back value 0 INSTEAD of 66 wich ist stored in byte 1004
I hope you can see that you have to take care of the variabletypes very much if your code uses POINTERS.
And this is a very good example why it makes sense to understand the code in medium detail-deph
Using code with NO understanding at all leaves you in the position of COMPLETE dependence of others
As soon as a strange problem occurs you have to ask an expert about this.
Again my question: do you know how to use FullDuplexSerial to send debug-information to the PC ?
yes or no
best regards
Stefan
Yes I do know how to use FullDuplexSerial to send information to a PC terminal.
I have a tv connected and would prefer to use that for debug.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
1. Getting output_time and output_command to be byte arrays.
2. Getting output_command to have prefixed 0's.
3. An if statement to check if each numeral in output_command is a 1 or a 0.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE