The circuit is extremely simple, we just need to wire up a push button to GPIO 12 and GND. As the OS believes this is “just a mouse” the project can be used on any OS. CircuitPython will automatically run code.py (MicroPython can also do this with main.py and boot.py) when the Pico is connected to the computer. Save the code as code.py to your Raspberry Pi Pico (CircuitPython device). Move the mouse up 10 pixels, print a message and then again pause. Move the mouse down 100 pixels, print a message and then another pause. Now move the mouse 100 pixels to the right, print another message and pause for a further half second. ![]() Print a message to the Python shell and pause for half a second. Use “move” to move the cursor 100 pixels to the left. while True:Īlternative Testing For Loop for i in range(2):ġ0. For testing purposes this loop can be replaced with a for loop, otherwise the code would lock us out of working. Create a loop to continuously run the code within. ![]() Create an object, m, to control the virtual mouse. ![]() We will use this to add a short delay between each movement. Import the sleep function from the time library. Import the USB_HID library, followed by Adafruit’s Mouse support library. Click on File > Open and open code.py on the CircuitPython device (our Raspberry Pi Pico).Ħ. Thonny will now connect to the Pico W running CircuitPython.Ĥ. Select Interpreter, then set the interpreter as CircuitPython, port to automatic, and click OK.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |