Passing a variable to a gosub...?

Mikler

Member
Newbie advise please....

How do I define and then send a variable to a gosub that typically
"variable" would be 'portc 2' or 'out 2' etc


An example of my gosub:

ramp_up:

for b0 = 1 to 100
low "variable"
pauseus 100
high "variable"
next b0

Return
 

SD2100

New Member
You won't be able to put 'portc 2' or 'out 2' into the variable just a value like 2 etc. eg: high b1 or high portc b1

Put the value into the variable for the output you want to use then do the gosub, if your mixing normal outputs and portc you might have to set another variable to select which port you want to use.
Code:
main:
    b1 = 2   'Output
    b2 = 0   'Port ---- 0 = normal output, 1 = Portc
    gosub ramp_up
goto main

ramp_up:
for b0 = 1 to 100
    select case b2 
        case 0
            low b1
            pauseus 100
            high b1
        case 1
            low portc b1
            pauseus 100
            high portc b1
    end select		
next b0
Return
You can also use the PINS and PINSC for turning outputs on/off
 
Last edited:

SilentScreamer

Senior Member
You won't be able to put 'portc 2' or 'out 2' into the variable just a value like 2 etc. eg: high b1 or high portc b1

Put the value into the variable for the output you want to use then do the gosub, if your mixing normal outputs and portc you might have to set another variable to select which port you want to use.
Code:
main:
    b1 = 2   'Output
    b2 = 0   'Port ---- 0 = normal output, 1 = Portc
    gosub ramp_up
goto main

ramp_up:
for b0 = 1 to 100
    select case b2 
        case 0
            low b1
            pauseus 100
            high b1
        case 1
            low portc b1
            pauseus 100
            high portc b1
    end select		
next b0
Return
You can also use the PINS and PINSC for turning outputs on/off
For the port why not use a bit variable, depending on if you need the extra variable space?
 
Top