Python programs not working with mbot neo


#1

Here are example two programs which fail
The first one :

import cyberpi
import time

cyberpi.pocket.motor_stop('m1')
while True:
    if cyberpi.controller.is_press("a"):
        cyberpi.pocket.motor_set(100,'m1')
        time.sleep(0.3)
    if cyberpi.controller.is_press('b'):
        cyberpi.pocket.motor_stop('m1')
        time.sleep(0.3)

it doesn’t show anything to the console, doesn’t react to the keys …
In case of second attempt :

# generated by mBlock5 for CyberPi
# codes make you happy

import event, time, cyberpi

@event.is_press('a')
def is_btn_press():
    # DO SOMETHING
    cyberpi.pocket.motor_set(100,'m1')
    time.sleep(3)
    cyberpi.pocket.motor_stop('m1')

I get :
>>
Traceback ( most recent call last):
File “main” ,
line 11, in
<module>
<<
and Line 11 refrences the last line of the program above…

I am on windows 8 and use mlink2 with Chrome’s web browser and makeblock application in it. Wish I could at least see error logs of those programs …


#2

For the first one try this :

import cyberpi, time
    cyberpi.pocket.motor_stop('m1')
    while True:
        if cyberpi.controller.is_press("a"):
            print("a")
            cyberpi.pocket.motor_set(100,'m1')

        if cyberpi.controller.is_press('b'):
            print("b")
            cyberpi.pocket.motor_stop('m1')
        
        time.sleep(0.3)

For the second one I have no error.

I am on windows 10 and use mBlock v5.4.0 on my computer.


#3

Hello, @paul424, I believe you received a correct reply from @PierreJo. Maybe you should thank him?
Screenshot%202022-06-20%20at%2019-49-36%20mBlock%20Extension%20Builder%20-%20Create%20your%20own%20extensions%20for%20mBlock

Thanks for your time,
Best_codes