I am a programmer from team 623. I was wondering if there is any website/document with DEFINITIVE information on the syntax of the PBASIC programming language. I’ve been to Innovation First and I got the programming reference guide, but the syntax isn’t explained too well. I can do some guess work by looking at the sample programs but I still need more info.
Aside from that, a have a more specific question about the MIN and MAX keywords in the sample program. What do they do exactly? Right now that is the keyword that I really need info on.
Note: Im posting under a fellow team member’s name. Later, when I get my new computer, I will be posting as “EbonySeraphim.”
These two statememts ask PBASIC to check if the result of the calculation they follow is a minimum of, ar a maximum of the stated value.
x = 30 * datav MIN 60 MAX 120
will do the operation 30 times datav, then if datav was only 1 or zero, MIN would return a value of 60. If datav is 2, 3 or 4, the result is passed through. If datav > 4 then MAX will replace the product with 120
Since the Stamp only uses integer arithmetic, there are no other values of datav to worry about. Heh heh heh, not so fast !
Some people mess it up with MIN 0. if a=4 and b=5 in your program and x = a - b MIN 0 is used, the result a-b is more than zero, because -1 is 255 in the 8-bit world. 255 passes MIN 0 with flying colours. Similarly, with byte variables, (253 + 3) MAX 256 appears to do nothing giving 1 as a result.
To work around this eight-bit under/overflow, we add 2000, so the arithmetic has to be done 16 bits wide.
x = (((a + 2000) - b) MIN 2000) - 2000
will return 0, because the result of the original subtraction was 1999, a positive integer, but it will be replaced by MIN with 2000, the MINimum allowable value.
The PBASIC manual is availible from Parallax. Note that this does not cover the pbasic 2.5 syntax. If you want to use that, you will need to search other posts. However, it is not necessary to use the new syntax (and things like min and max didn’t change) so the manual is all your really need.