![]() We now start a loop that keeps running as long as button Y hasn’t been pressed. Why 6 and 15 when there are 7 rows of 16 LEDs on the Unicorn Pack? Because the first row and first column of each is counted as 0, not 1. The first job is to define the variables we’ll be using, which include values for the red and green mix in the colours we want to display (red for work, green for rest), and a column and row count. We’ve called this process pomocycle, as detailed on line 6. We’ll define a process that can be kicked into action as soon as the X button is pressed. Then, every time one 112th of a cycle has passed – 13.4 seconds on a work cycle and 2.7 on a rest cycle – we’ll extinguish one of the LEDs on the Unicorn Pack. We’ll use the utime library to count the length of each work and rest cycle – which are 25 minutes (1500 seconds) and five minutes (300 seconds) respectively – and divide the number of seconds in each stretch by 112. The first three lines of code set up the environment in which our program will run by referencing the libraries that handle time and the specific features of our Unicorn Pack add-on. Make sure you save your code regularly as main.py and, when asked where you want to save, choose ‘Raspberry Pi Pico’. Click Python in the lower-right corner of the Thonny window and select ‘MicroPython (Raspberry Pi Pico)’ from the list of options to redirect its output – you’re now ready to start coding. By default, it works with and executes code stored locally, but we want to address Pico directly so that we can take advantage of the custom firmware. We’ll code Pico using the Thonny Python IDE, which is included in Raspberry Pi OS, and free for Windows and macOS ( ). It will then reboot with the updated firmware. ![]() When it appears, drag the UF2 file from your Downloads folder onto Pico. Press and hold Pico’s BOOTSEL button while plugging it into a USB port on your computer (Raspberry Pi, PC, or Mac). Point your browser at /pimoronipicoreleases and download the most recent UF2 (.uf2) file – examples for use are at /pimoronipicogit. Instead, you need Pimoroni’s custom MicroPython firmware image. Your Pico contains a web link to Raspberry Pi’s own firmware, but this doesn’t include the additional hooks required to work with the Unicorn Pack. Be firm but gentle and try to keep equal pressure on either end to reduce the risk of bending any pins on either of the headers. Line up this illustration with the actual USB socket, then press the Unicorn Pack onto the header pins on Pico. Now check the back of the Unicorn Pack, where you’ll see there’s a white painted illustration of Pico’s USB socket. ![]() When the solder has had time to cool, turn over Pico so that the longer end of each pin is pointing up and the USB socket is underneath. Don’t allow solder to stray across adjacent strips or pins, or you’ll create a short circuit. With the USB socket uppermost, fit Pico over the shorter pins on either header and use a small amount of solder on each one to create a contact with the corresponding metal strip on Pico. ![]() We want to attach Pico to a hardware array of LEDs – but, as Pico lacks the GPIO header of a regular Raspberry Pi, we’ll first need to solder a header to the long row of holes on either side of Pico itself. ![]() But pairing a Raspberry Pi Pico with the bright LEDs of a Unicorn Pack means you can see at a glance when your next break is approaching and, if you keep it just out of your eyeline, that warm red glow is a reminder to carry on working. ![]()
0 Comments
Leave a Reply. |