I'm assuming that this question is about the PICAXE microcontroller and its BASIC language, because of the [picaxe]
tag. There are several things in the posted code that won't work in PICAXE BASIC so I guess you're familiar with a different dialect or are trying to take some code written for a different dialect and use it on a PICAXE. If this isn't the case, please let us know.
To get this code to work on a PICAXE you need to fix a few things:
- You can't just assign to a new variable name; you need to use the built-in names
b0
, b1
, b2
etc (byte variables) or w0
, w1
, w2
etc (word variables) unless you define another name for it using the symbol
keyword.
- To generate a random number, use the
random
keyword which assigns a random value to the word variable you specify.
- You can only use the one-line
if … then
command with goto
, gosub
or exit
. Otherwise you need to use an if … then … endif
structure, but you can write this on a single line using :
to separate the commands.
- Finally, to specify a binary value you prefix it with a
%
character.
So I think what you're trying to do is this:
symbol a = w0 ; use the name 'a' for word variable w0
random a ; assign a random value of 0...65535 to a
a = a // 10 + 1 ; // is modulo i.e. remainder of a / 10, so result is in range 1 - 10
if a = 1 then : pinsB = %01110111 : endif
if a = 2 then : pinsB = %00010100 : endif
if a = 3 then : pinsB = %10110011 : endif
if a = 4 then : pinsB = %10110110 : endif
if a = 5 then : pinsB = %11010100 : endif
if a = 6 then : pinsB = %11100110 : endif
if a = 7 then : pinsB = %11100111 : endif
if a = 8 then : pinsB = %00110100 : endif
if a = 9 then : pinsB = %11110111 : endif
if a = 10 then : pinsB = %11110100 : endif
Always remember that each word variable is made up of two byte variables, so if you've used w0
you can't also use b0
or b1
at the same time, and so on.