Mathmatics Problem - 'Is Not' symble

Solitaire

New Member
Hi,

I have used the PICAXE many times before and I have become familiar with most of the commands in the "Command Summary" adobe file. I am doing a comparison between variables and I am looking for a way of doing a 'is not equal' to equation. I know that in many languages you can type != .

Here is the code I am trying to shorten:


if pin0=1 and b1 = 1 then decay1

if pin0=1 and b1 = 2 or b1 = 3 or b1 = 4 or b1 = 5 or b1 = 6 or b1 = 7 or b1 = 8 or b1 = 9 or b1 = 0 or b1 = 11 or b1 = 12 then lock


As you can see it is very long, and I have about two hundred copies of this code in my program, and hence it will not fit on a 600-line pic.

Ideally I would like to be able to put:

if pin0=1 and b1 = 1 then decay1
if pin0=1 and b1 != 1 then lock

Is there another way? :( I am in need of help here.

The code says:
When button 0 is pressed if b1=1 then do this, if b1= another of the other 12 numbers do XXX.

I cannot do an "else" statement. The reasons for this are very long and complex. Any ideas?

Yours thankfully,
Joe Valentine
 

Solitaire

New Member
I had an idea. Instead of using

pin0=1 AND b3 != 1

i could do

pin0=1 AND [ b3>1 OR b3<1 ]

anyone know the correct PBASIC coding?
 

hippy

Ex-Staff (retired)
You are heading in the right direction. The PICAXE 'is not' / 'not equal to' operator is '<>', it's the equivalent of '!=' in other programming languages.

So 'IF pin0 = 1 ...' is the same as 'IF pin0 <> 0' as the only valid values for pin0 are zero and one; that is effectively an "IF NOT".

In addition to = and <>, there are also >, >=, < and <= which are relative value comparisons ...

- IF bo > 10 THEN ... ' Branch when b0 greater than 10

Your long IF ...

- if pin0=1 and b1 = 2 or b1 = 3 or b1 = 4 or b1 = 5 or b1 = 6 or b1 = 7 or b1 = 8 or b1 = 9 or b1 = 0 or b1 = 11 or b1 = 12 then lock

can be shortened by using the comparison operators. You branch when pin0 is 1 and b1 has a value betwen 2 and 12 inclusive. Or, to put it another way, when pin0 equals 1 and b1 is greater or equal to 2 and b1 is less than or equal to 12 ...

- IF pin0 = 1 AND b1 >= 2 AND b1 <= 12 THEN Lock
 

alanchrislewis

New Member
Didn't know where to post this but in the maths section. Using the 'count' command a value can be
stored up to 16 bits in the w1 register. by counting over on second
the result in the w1 register is directly in Hertz even if the
mark,space ratio is uneven. found the "serttxd" command useful for
sending the result directly back to the PC using hyperterminal down
the existing programming lead. It was nice to have the ability to mix
ascii commands, text and data. The result in the w register is sent
as an ascii string and doesn't need hundred, tens and units stripping
down to individual ascii characters as with command "serout". The
only problem I found with "serttxd was that a cr command was added at
the end of each line of basic. If this did not occure then we could
drive the LCD module direct, overwriting the previous line of text.
If anybody has any ready routines for stripping out 100,10 and ones
from a register I would be grateful. I no it's just a case of
subtracting 100 and incrementing a 100's register but I 'm worried
about getting negative numbers if we take too much off

Regards Chris Lewis ( UK member )



 
 

Technical

Technical Support
Staff member
sertxd does not add a CR, this must be in your code or in the receiving computer software.
 
Top