Quote:
Originally Posted by TimTheGreat
The good (and bad) thing about motors is if you don't tell them what to do, they'll do the last thing they were told. This means if you forget to set a motor to 0 when you're done with it it will stay turned on. You can use this to your advantage
Code:
if state == 1:
motor.set(1)
state = 2
if state == 2:
do_pneumatic_stuff()
#because the motor hasn't been set to 0, it's still set to 1
if pneumatic_stuff_done:
state == 3
if state == 3
motor.set(0) #Now we set it to 0 to stop it
|
While you're right that this technique works, I highly recommend against it. Instead, I would explicitly set the motor in each branch, so you can be absolutely sure that the motor is doing what you want.
But, you can do something like this:
Code:
if self.state == 1:
self.piston.fire()
elif state == 2:
something_else
..
self.motor.set(1)
As you can see, as long as the motor setting is *always* happening and isn't excluded by some if statement, then you're fine.