Using a Breakout Button

Jul 2026

Introduction

*** Warning *** You can lock yourself out of your Pi Pico if you don't have a method to break the code. Please think about if you want/need to do this!!!
In the previous example, we used some code to cause a 20 second start delay, so you had 20 seconds before the code ran where you could use Thonny to stop the process before it properly started. However, once 20 seconds had elapsed, this would no longer work. So you needed to reboot the Pico and break in before the 20s start delay.
In this example, again we are going to use the traffic light example, we are going to use a button to breakout of our code. This is very simple to do, first lets look at the wiring diagram for our traffic lights.
This is our original traffic light build, but with an additional push button on pins GP16 and GND.

The Code

Below is the code, there are two blocks that have been added. The are:

Block1 - Sets up GP16 as an input that is pulled up (so we need to set it to GND for it to work)

Block2 - Monitors the button to see if it is pressed (looking for a zero on Pin16)

Block1 is at the program start, and is only run once.

Block2 is in the loop, and is checked every time the code loops.