Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to have multiple functions to control the Lego hub motors not Just the run() function #14

Open
wobeix opened this issue May 20, 2020 · 0 comments

Comments

@wobeix
Copy link

wobeix commented May 20, 2020

I want to use this library in a special way, i need your help (i use the control+ hub)
my main file is (main.py):

import curio
import train

if __name__ == '__main__':
    curio.run(train.main()) # this works
    curio.run(train.move()) # this doesn't 

The second file is train.py

from curio import sleep
from bricknil import attach, start
from bricknil.hub import CPlusHub
from bricknil.sensor.motor import CPlusLargeMotor

@attach(CPlusLargeMotor, name='motor_A')
@attach(CPlusLargeMotor, name='motor_B')
class Train(CPlusHub):

    async def run(self):
        await self.motor_A.set_speed(+100)
        await sleep(2)

    async def move_forward(self):
        await self.motor_A.set_speed(-100)
        await self.motor_B.set_speed(-100)
        await sleep(2)

async def system():
    train = Train('My train')

async def main():  
    start(system)

async def move():
    train = Train('My train')
    await train.move_forward()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant