say I:
motor_forward = machine.Pin...
motor_backward = machine.Pin....
& I wish to create 2 routines
def forward():
backward():
is it possible to initialise the pin's within the main body of code & gain access to them within my sub routines...?
or
is it possible to initialise the pins within there own routine e.g. def init():, run the init routine and still gain access to the pins via
other routines...
Noob: access to variable assigned Objects
Re: Noob: access to variable assigned Objects
If you declare these pin objects as global in the functions, you can access them within the functions. For the declaration, just write:
global motor_forward, motor_backward
That's a Python property.
global motor_forward, motor_backward
That's a Python property.
Re: Noob: access to variable assigned Objects
You can also pass things around as arguments:
which has the benefit it keeps on working when you add more motors
Code: Select all
def forward(motor):
motor.high()
motor.low()
def backward(motor):
motor.low()
motor.high()
def main()
motor_forward = machine.Pin...
motor_backward = machine.Pin....
forward(motor_forward)
backward(motor_backward)
Re: Noob: access to variable assigned Objects
Thank you for the example reply