# Integer Increment to Subroutine Sending Serial Data

#### SolidWorksMagi

##### Senior Member
Hi,

I'm trying to figure out how to send 70 different serial data strings one string at a time using a momentary switch.

I know how to sense the momentary switch, but I need to send different serial data each time I press on the switch.

I can set an integer and increment the integer, but I don't know how to translate that integer to a subroutine name.

e.g.,
symbol integer = w0
integer=0
do
IF Switch = 1 then gosub ???
integer = integer + 1
loop

1:
serout C.2,T4800_8,(0XE3,0x02,0x16,0x74,0x0E,0x00)
return
2:
serout C.2,T4800_8,(0XE3,0x03,0x60,0x48,0x10,0x00)
return
3:
serout C.2,T4800_8,(0XE3,0x03,0x44,0x75,0x13,0x00)
return

But I can't really use 1, 2 and 3 as subroutine names.

Last edited:

#### cpedw

##### Senior Member
For that application, I would forget subroutines and use Select Case instead of If.
Derek

#### AllyCat

##### Senior Member
Hi,

It depends if you just want to change one byte in each "string"? In that case some form of "lookup" would be best, either a "Table" in EEPROM or TABLE memory (if the specific PICaxe has it) or with a LOOKUP instruction.

Code:
``````symbol integer = w0
symbol number = b2
DATA 0 , (\$43 , \$72 , \$A4 )
do
READ integer , number        ; Or: LOOKUP integer , (\$43 , \$72 , \$A4 , ....) , number ;  etc.
SEROUT 7 , N2400 , (0x00 , number)
integer = integer + 1
loop``````
Alternatively, if you actually want to use sequential numbers to go to different (Sub-)Routines then there are the ON .... GOTO ... and ON .... GOSUB .... instructions which are potentially much faster and more compact. It's the method that I used to transmit 96 (and more) different data strings to an I2C display, shown in post #2 of THIS CODE SNIPPET.

And for those who "hate" GOTOs, the BRANCH instruction does exactly the same thing.

Cheers, Alan.