Import the library
The first thing in the program tells Pybricks "I want to use the Controller library". Without this line the hub does not know what MBC_GAMEPAD means, and you get a NameError.
Pick one library (both work exactly the same; only the import line is different):
- Download the library (save the file and keep its name): MBC_gamepad.py (only this sensor) or MBC_sensors.py (the all-in-one library). You picked
MBC_gamepad.py. - In Pybricks Code, press "Import a file" in the file area on the left and import it into the same project.
- Do not rename the file, and do not put it in a subfolder.
- Go back to your main program and type the lines below at the very top (marked ① in the program on the right).