# CircuitPython OLED and Dual Knob Sketcher

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/068/445/medium800thumb/circuitpython_movie.jpg?1546208034)

In this guide we will create a simple knob sketcher toy using a graphical display and two potentiometers, also known as trim pots or just pots. We'll go over the basic idea of drawing a pixel to the display as well as how to use the pots to generate a variable voltage. The two concepts will be put together to create a couple different variations of a knob sketcher toy.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/431/medium800/circuitpython_banner.jpg?1546112566)

## Parts

This guide uses an Adafruit ItsyBitsy M4 Express as the main board. However, you could adapt this to other boards that run CircuitPython and have the available pins. You might need to change the example code to match the pins for your board.

### Adafruit ItsyBitsy M4 Express featuring ATSAMD51

[Adafruit ItsyBitsy M4 Express featuring ATSAMD51](https://www.adafruit.com/product/3800)
What's smaller than a Feather but larger than a Trinket? It's an **Adafruit ItsyBitsy M4 Express** featuring the **Microchip ATSAMD51**! Small, powerful, with a ultra fast ATSAMD51 Cortex M4 processor running at 120 MHz - this microcontroller board is perfect...

In Stock
[Buy Now](https://www.adafruit.com/product/3800)
[Related Guides to the Product](https://learn.adafruit.com/products/3800/guides)
![Adafruit ItsyBitsy M4 Express featuring ATSAMD51 connected to a small breadboard. ](https://cdn-shop.adafruit.com/product-videos/640x480/3800-04.jpg)

The other key part for this project is a graphical display. This guide uses the two displays below, but you could also substitute for other similar displays as long as there is a CircuitPython driver available.

### Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic

[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/938)
[Related Guides to the Product](https://learn.adafruit.com/products/938/guides)
![Monochrome 1.3" OLED module with Adafruit logos falling like snow](https://cdn-shop.adafruit.com/product-videos/640x480/938-05.jpg)

### Monochrome 2.42" 128x64 OLED Graphic Display Module Kit

[Monochrome 2.42" 128x64 OLED Graphic Display Module Kit](https://www.adafruit.com/product/2719)
If you've been diggin' our [monochrome OLEDs](https://www.adafruit.com/categories/98) but need something bigger, this display will delight you!&nbsp;These displays are **2.42" diagonal** , and very readable due to the high contrast of an OLED display. This...

In Stock
[Buy Now](https://www.adafruit.com/product/2719)
[Related Guides to the Product](https://learn.adafruit.com/products/2719/guides)
![Animation of lines drawing on a Monochrome 2.42" 128x64 OLED Graphic Display.](https://cdn-shop.adafruit.com/product-videos/640x480/2719-11.jpg)

You'll need a pair of potentiometers also. The two options used in this guide are linked below. Pots are also pretty common things, so any similar ones would likely work.

### Breadboard trim potentiometer

[Breadboard trim potentiometer](https://www.adafruit.com/product/356)
These are our favorite trim pots, perfect for breadboarding and prototyping. They have a long grippy adjustment knob and with 0.1" spacing, they plug into breadboards or perfboards with ease.

This is the same pot that comes with our character LCDs and tutorial...

In Stock
[Buy Now](https://www.adafruit.com/product/356)
[Related Guides to the Product](https://learn.adafruit.com/products/356/guides)
![Breadboard friendly trim potentiometer](https://cdn-shop.adafruit.com/640x480/356-03.jpg)

### Panel Mount 10K potentiometer (Breadboard Friendly)

[Panel Mount 10K potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/562)
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are 0.2" apart...

In Stock
[Buy Now](https://www.adafruit.com/product/562)
[Related Guides to the Product](https://learn.adafruit.com/products/562/guides)
![Breadboard Friendly Panel Mount 10K potentiometer linear.](https://cdn-shop.adafruit.com/640x480/562-00.jpg)

In addition, you'll need a breadboard and some hookup wires. A button is used for the second knob sketcher. Details are provided later in the guide.

### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
![Angled shot of full sized breadboard.](https://cdn-shop.adafruit.com/640x480/239-03.jpg)

### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)
![Bundle of multi-colored multi-length wire jumpers](https://cdn-shop.adafruit.com/640x480/153-04.jpg)

# CircuitPython OLED and Dual Knob Sketcher

## Software Setup

The code in this guide is written in CircuitPython. So, before proceeding, make sure you have CircuitPython and the latest libraries installed on your board.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/438/medium800/circuitpython_circuit_playground_adafruit_blinka_computer.png?1546137183)

If you are new to CircuitPython, read these guides first. They will explain how to install CircuitPython and the necessary libraries.

- [Welcome to CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/overview)
- [CircuitPython Essentials](https://learn.adafruit.com/circuitpython-essentials/circuitpython-essentials)

They also cover how to load and run code, access the REPL for troubleshooting, etc.

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython.&nbsp;[You can learn about Mu and its installation in this tutorial](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

# CircuitPython OLED and Dual Knob Sketcher

## Drawing Pixels

Many graphics libraries ([like this one](https://learn.adafruit.com/adafruit-gfx-graphics-library/overview)) will provide functions for drawing various graphical primitives like lines, circles, squares, etc. But we will only need one very simple primitive for this project - the lowly pixel. There is a good discussion about the pixel and associate coordinate system in the [GFX guide](https://learn.adafruit.com/adafruit-gfx-graphics-library/overview). The excellent figure below is borrowed from that guide. Think of this as looking at the front of your display.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/316/medium800/circuitpython_lcds___displays_coordsys.png?1545963693)

The coordinate system starts in the upper left hand corner of the display. To specify a pixel location, you provide the x value and the y value in the form (x, y). This is another one of those computer things where counting starts at 0. Therefore, the very first pixel in the upper left hand corner is (0, 0). The x value is how far to the right, and the y value is how far down. In the figure above you can see two other pixels for x=6, y=13 =\> (6, 13) and for x=18, y=6 =\> (18, 6).

The other thing to note is that every display will have an associate `width` and `height`. This is basically the total number of pixels in each direction. For the example above, the width would be 24 and the height would be 16. Note that the last pixel coordinates are 23 in x and 15 in y. That's due to the counting from 0 thing again. So to draw the very last pixel - all the right, all the way down, the coordinates would be (width -1, height -1).

# One Little Pixel

Let's wire up a display and play around with drawing pixels.

The diagram below shows how to wire up a [1.3" OLED](https://www.adafruit.com/product/938) to an [ItsyBitsy M4 Express](https://www.adafruit.com/product/3800). The connection uses I2C, which is covered in the guide for the OLED, so be sure to [read that first](https://learn.adafruit.com/monochrome-oled-breakouts/wiring-128x64-oleds#using-with-i2c-4-5).

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/068/381/medium800/circuitpython_Itsy_OLED_bb.jpg?1546032194)

OK, here's the code. You can either save this as **code.py** to have it run automatically, or you can save it to another file name and run it manually.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Knob_Sketcher/pixel_simple/code.py

Info: 

Once you have that code loaded and it runs....voila! There's the pixel! Do you see it? It's super tiny on this little display, but there it is. It's so cute. I think I'll call it Dotty. Hi, Dotty!

![](https://cdn-learn.adafruit.com/assets/assets/000/068/385/medium800/circuitpython_oled_pixel_circ.png?1546033816)

And Dotty showed up right where we said to, 42 pixels to the right and 23 pixels down.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/387/medium800/circuitpython_oled_pixel_coord.jpg?1546033897)

If you want to have Dotty show up in another location, edit these two lines of code:

```
x = 42
y = 23
```

and run the program again.

## It's Full of Stars

Let's give Dotty the lowly pixels some friends. Lots of friends. To do that, we will draw more pixels. You can call the `display.pixel()` function as many times as you want to draw more than one pixel. Let's have some fun with that. Here's a program that draws 500 pixels in random locations. It does this over and over again, pausing for half a second each time.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Knob_Sketcher/pixel_play/code.py

Approximately twice a second the display will update with a random pattern of stars. Or is it snow? And where'd Dotty go? Lost in the snow storm I guess. Bye, Dotty!

![](https://cdn-learn.adafruit.com/assets/assets/000/068/388/medium800/circuitpython_full_o_starz.jpg?1546033939)

And that's all there is to draw one or more pixels. Don't forget to call `display.show()` to actually see the results though.

# CircuitPython OLED and Dual Knob Sketcher

## Reading Pots

We want some way to control the location of the pixel using some form of input. For our knob sketcher, we will use a couple of pots. One to control left and right, and one to control up and down.

So what is a pot? A thing you put dirt and plants in? Or the thing you make soup in? Well, yes. But in electronics, it is short for _potentiometer_. So what is a potentiometer? It's a fancy word for a resistor with a variable value. How do you vary the value of this variable resistor? Easy - with a knob. Just grab it, turn it, change it.

Let's take a closer look.

## Pot Internals
Let's start by looking at a normal resistor with a fixed value. These are super common and look something like the image below. The actual resistor is shown on the left and one way of representing it in drawings is shown on the right.

![circuitpython_r1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/353/medium640/circuitpython_r1.jpg?1546194903)

The color bands can be used to determine what the actual value of the resistors is. But that's not important for what we are doing here. Let's just call it **R1**.

Now consider two resistors put together so they are connected together. Like this!

![circuitpython_r2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/354/medium640/circuitpython_r2.jpg?1546194929)

Now there are three leads as shown in the drawing on the right. Again, we are not concerned about the actual value of the second resistor, so we are just calling it **R2**.

This is basically what the inside of a potentiometer has. So those two resistors become our pot.

![circuitpython_r2_pot.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/355/medium640/circuitpython_r2_pot.jpg?1546194967)

And to better illustrate what the three tabs are doing.

![circuitpython_pot_res.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/414/medium640/circuitpython_pot_res.jpg?1546194994)

But where is the variability? Are **R1** and **R2** fixed values and that's all there is to it? No. The way a pot works is you can change the values of **R1** and **R2** by turning the knob. They don't change separately. The total resistance obtained by adding **R1** and **R2** together will always be the same - the overall value for the pot.

The pot shown above is a fairly common 10k pot. That means its total resistance is 10,000 ohms. So:

![](https://cdn-learn.adafruit.com/assets/assets/000/068/364/medium800/circuitpython_eq_rtot.jpg?1546027773)

The knob will change the values of **R1** and **R2** , anywhere from 0 up to 10000. But the above relation will always hold. For this style pot (linear), the variation would look something like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/068/436/medium800/circuitpython_pot_values.jpg?1546135494)

If you just wanted to use a pot as a single variable resistor, you could. You would just use the middle connector and only _one_ of the outer connectors. Then you would have a resistor that would vary from 0 to 10000 as the knob is turned.

However, we are going to use all three pins in an arrangement known as a voltage divider. So let's look at that in a little more detail.

## Variable Voltage Divider
Here is how to wire up the pot to create a voltage divider.

![circuitpython_pot_divider.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/415/medium640/circuitpython_pot_divider.jpg?1546195020)

You could use [Ohm's Law](https://learn.adafruit.com/circuit-playground-o-is-for-ohm/video) on this to figure out how it works, but we'll just give you the answer. Here it is:

![](https://cdn-learn.adafruit.com/assets/assets/000/068/365/medium800/circuitpython_eq_vdiv.jpg?1546027781)

In our case, we will have **Vin** be a constant value (3.3V). As we turn the knob on the pot, we will change **R1** and **R2** as described previously and therefore get a varying **Vout**. Consider the limiting cases of turning the knob all the way in either direction.

All the way in one direction (not the boy band!) will produce **R1 = 0, R2 = 10000**. The fraction then becomes 1 and we get **Vout** = **Vin**.

All the way in the other direction (is that a boy band?) will produce **R1 = 10000, R2 = 0**. The fraction then becomes 0 and we get **Vout** = **0**.

Knob positions in between these two limits will produce different values, and so will "divide" the input voltage down to some value.

The result looks something like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/068/439/medium800/circuitpython_pot_volts.jpg?1546137760)

Let's wire this up and see it in action.

## Try It Yourself

The variable voltage divider setup is shown below. **Vin** (red wire) is wired to 3.3V ( **3V** ) and **Vout** (yellow wire) is wired to one of the analog inputs ( **A0** ) so we can measure the resulting voltage. The other wire (black wire) goes to GND ( **G** ).

![](https://cdn-learn.adafruit.com/assets/assets/000/068/379/medium800/circuitpython_Itsy_small_pot.jpg?1546031924)

Here is a short CircuitPython program that simply reads the analog input value over and over in a loop and prints it out.

```
import time
import board
from analogio import AnalogIn

knob = AnalogIn(board.A0)

while True:
    print((knob.value, ))
    time.sleep(0.2)
```

We aren't worried about computing actual volts, so we just look at how the raw reading varies as we turn the knob. If you have Mu installed, this a good use for [its builtin plotter](https://learn.adafruit.com/make-it-graph-plot/circuitpython-and-mu).

![](https://cdn-learn.adafruit.com/assets/assets/000/068/369/medium800/circuitpython_Screenshot_from_2018-12-28_12-32-20.jpg?1546029248)

With that code running you can turn the knob and watch the value change. Since we are not reading volts, it will vary in terms of raw values, which will be 0 to 65535 ([more info](https://circuitpython.readthedocs.io/en/latest/shared-bindings/analogio/AnalogIn.html#analogio.AnalogIn.value)). You may not get all the way to these values since the pot isn't perfect.

# CircuitPython OLED and Dual Knob Sketcher

## Tiny Sketcher

Let's put these two things together - drawing pixels + reading pots, to create our knob sketcher toy. We'll start with a minimalistic version called the Tiny Sketcher.

In addition to the ItsyBitsy M4, the Tiny Sketcher uses these parts.

### Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic

[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/938)
[Related Guides to the Product](https://learn.adafruit.com/products/938/guides)
![Monochrome 1.3" OLED module with Adafruit logos falling like snow](https://cdn-shop.adafruit.com/product-videos/640x480/938-05.jpg)

### Breadboard trim potentiometer

[Breadboard trim potentiometer](https://www.adafruit.com/product/356)
These are our favorite trim pots, perfect for breadboarding and prototyping. They have a long grippy adjustment knob and with 0.1" spacing, they plug into breadboards or perfboards with ease.

This is the same pot that comes with our character LCDs and tutorial...

In Stock
[Buy Now](https://www.adafruit.com/product/356)
[Related Guides to the Product](https://learn.adafruit.com/products/356/guides)
![Breadboard friendly trim potentiometer](https://cdn-shop.adafruit.com/640x480/356-03.jpg)

### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
![Angled shot of full sized breadboard.](https://cdn-shop.adafruit.com/640x480/239-03.jpg)

&nbsp;

The breadboard setup is shown below. The display has been rotated, but is otherwise wired the same as before. A second pot has been added, but they are both being used in the same way - as variable voltage dividers. The outputs are sent to different analog inputs.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/418/medium800/circuitpython_Itsy_small_pots_small_OLED_bb.jpg?1546045511)

And here is the CircuitPython code to create the sketcher.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Knob_Sketcher/tiny_sketcher/code.py

Info: 

Most of this code is just setup. All the work to create the sketcher is done in the last 5 lines.

```
while True:
    x = map_range(x_knob.value, 0, 65535, WIDTH - 1, 0)
    y = map_range(y_knob.value, 0, 65535, 0, HEIGHT - 1)
    display.pixel(int(x), int(y), 1)
    display.show()
```

We read each of the knob values using the `value` property. To turn those values into a pixel location, we use the very handy function `map_range`. This function is so handy, it's a wonder why it wasn't built into the Python core. Instead, it is provided by the **simpleio** library - [more info here](https://circuitpython.readthedocs.io/projects/simpleio/en/latest/api.html#simpleio.map_range). It basically converts one range of values into another range of values. In this case, from the range of analog read values, 0 to 65535, to the range of pixel locations, 0 to WIDTH or HEIGHT. (the - 1 is because of 0 indexing)

Note that the directionality of the knobs can be changed by swapping the order of the last two parameters. If you don't like the direction the pixel moves when you turn the knob, just swap these two and it will reverse it.

Once we have converted the knob values to pixel location, we draw the pixel. The `int()` is needed since `map_range` returns a float and `pixel()` expects integers for the pixel location.

And then we just do that over and over again...forever!

![](https://cdn-learn.adafruit.com/assets/assets/000/068/432/medium800/circuitpython_tiny_sketcher.jpg?1546113165)

Run the code and turn the knobs. It should be obvious how it works. Sketch away!

Warning: 

# CircuitPython OLED and Dual Knob Sketcher

## Bigger Sketcher

Tiny Sketcher works just fine and demonstrates the basic idea of how the sketcher works. However, that tiny screen and those tiny knobs can be a little tricky to work with. And the only way to start a new sketch is to restart the program.

The Bigger Sketcher improves on Tiny Sketcher by using a larger screen, larger pot knobs, and adds a button that will erase the screen and start over.

In addition the the Itsy Bitsy M4, the Bigger Sketcher uses these parts.

### Monochrome 2.42" 128x64 OLED Graphic Display Module Kit

[Monochrome 2.42" 128x64 OLED Graphic Display Module Kit](https://www.adafruit.com/product/2719)
If you've been diggin' our [monochrome OLEDs](https://www.adafruit.com/categories/98) but need something bigger, this display will delight you!&nbsp;These displays are **2.42" diagonal** , and very readable due to the high contrast of an OLED display. This...

In Stock
[Buy Now](https://www.adafruit.com/product/2719)
[Related Guides to the Product](https://learn.adafruit.com/products/2719/guides)
![Animation of lines drawing on a Monochrome 2.42" 128x64 OLED Graphic Display.](https://cdn-shop.adafruit.com/product-videos/640x480/2719-11.jpg)

### Panel Mount 10K potentiometer (Breadboard Friendly)

[Panel Mount 10K potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/562)
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are 0.2" apart...

In Stock
[Buy Now](https://www.adafruit.com/product/562)
[Related Guides to the Product](https://learn.adafruit.com/products/562/guides)
![Breadboard Friendly Panel Mount 10K potentiometer linear.](https://cdn-shop.adafruit.com/640x480/562-00.jpg)

### Colorful Round Tactile Button Switch Assortment - 15 pack

[Colorful Round Tactile Button Switch Assortment - 15 pack](https://www.adafruit.com/product/1009)
Little clicky switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](http://www.ladyada.net/learn/arduino/lesson5.html). The pins are normally open (disconnected) and...

In Stock
[Buy Now](https://www.adafruit.com/product/1009)
[Related Guides to the Product](https://learn.adafruit.com/products/1009/guides)
![Top-down shot of 15 colorful round tactile button switches in green, yellow, red, blue, and white.](https://cdn-shop.adafruit.com/640x480/1009-07.jpg)

### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
![Angled shot of full sized breadboard.](https://cdn-shop.adafruit.com/640x480/239-03.jpg)

The connection uses SPI, which is covered in the guide for the OLED, so be sure to [read that first](https://learn.adafruit.com/1-5-and-2-1-monochrome-128x64-oled-display-module).

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/068/429/medium800/circuitpython_Itsy_big_pots_big_OLED_bb_oled.jpg?1546104887)

And here's the code for the Bigger Sketcher.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Knob_Sketcher/bigger_sketcher/code.py

As before, this code is largely setup. One big difference from Tiny Sketcher is how the knob values are determined. In order to smooth out possible noise in the analog readings, several readings are made and averaged together. This is all taken care of in the new function `read_knobs()`.

The other change is the addition of the button used to clear the display. This is handled with a simple modification of the previous loop.

```
while True:
    while clear_button.value:
        x, y = read_knobs(READS)
        display.pixel(x, y, 1)
        display.show()
    display.fill(0)
    display.show()
```

There is still the outer loop that runs forever - `while True:`. But now the pixel drawing is done in a new nested loop - `while clear_button.value:` . The way the button is wired, it will read `True` when it is **not** pressed. So this loop will keep running as long as the button is left alone. This is when you are drawing. Anytime you want to clear the current display, just hit the button. `clear_button.value` will return `False`, and the drawing loop will exit. The display is cleared by the last two lines, but then it starts all over again and you are back to drawing.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/430/medium800/circuitpython_bigger_sketcher.jpg?1546111826)

Warning: 

# CircuitPython OLED and Dual Knob Sketcher

## Going Further

The two example knob sketcher toys in this guide work well enough to demonstrate the basic idea and have some fun. However, there are lots of other "features" that cold be added. Here are some ideas in no particular order.

- A pen up / pen down capability
- Add an eraser capability
- `COLOR` display and control
- Save / load display to file
- Different brushes
- Connect skipped pixels with a line
- Accelerometer to erase on shake (for old skool feel)

Try adding one or more of these features using the provided code as a starting point. Or add some other cool feature. Have fun!

Info: 


## Featured Products

### Adafruit ItsyBitsy M4 Express featuring ATSAMD51

[Adafruit ItsyBitsy M4 Express featuring ATSAMD51](https://www.adafruit.com/product/3800)
What's smaller than a Feather but larger than a Trinket? It's an **Adafruit ItsyBitsy M4 Express** featuring the **Microchip ATSAMD51**! Small, powerful, with a ultra fast ATSAMD51 Cortex M4 processor running at 120 MHz - this microcontroller board is perfect...

In Stock
[Buy Now](https://www.adafruit.com/product/3800)
[Related Guides to the Product](https://learn.adafruit.com/products/3800/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
### Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic

[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/938)
[Related Guides to the Product](https://learn.adafruit.com/products/938/guides)
### Monochrome 2.42" 128x64 OLED Graphic Display Module Kit

[Monochrome 2.42" 128x64 OLED Graphic Display Module Kit](https://www.adafruit.com/product/2719)
If you've been diggin' our [monochrome OLEDs](https://www.adafruit.com/categories/98) but need something bigger, this display will delight you!&nbsp;These displays are **2.42" diagonal** , and very readable due to the high contrast of an OLED display. This...

In Stock
[Buy Now](https://www.adafruit.com/product/2719)
[Related Guides to the Product](https://learn.adafruit.com/products/2719/guides)
### Breadboard trim potentiometer

[Breadboard trim potentiometer](https://www.adafruit.com/product/356)
These are our favorite trim pots, perfect for breadboarding and prototyping. They have a long grippy adjustment knob and with 0.1" spacing, they plug into breadboards or perfboards with ease.

This is the same pot that comes with our character LCDs and tutorial...

In Stock
[Buy Now](https://www.adafruit.com/product/356)
[Related Guides to the Product](https://learn.adafruit.com/products/356/guides)
### Panel Mount 10K potentiometer (Breadboard Friendly)

[Panel Mount 10K potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/562)
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are 0.2" apart...

In Stock
[Buy Now](https://www.adafruit.com/product/562)
[Related Guides to the Product](https://learn.adafruit.com/products/562/guides)
### Colorful Round Tactile Button Switch Assortment - 15 pack

[Colorful Round Tactile Button Switch Assortment - 15 pack](https://www.adafruit.com/product/1009)
Little clicky switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](http://www.ladyada.net/learn/arduino/lesson5.html). The pins are normally open (disconnected) and...

In Stock
[Buy Now](https://www.adafruit.com/product/1009)
[Related Guides to the Product](https://learn.adafruit.com/products/1009/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)

## Related Guides

- [Extending CircuitPython: An Introduction](https://learn.adafruit.com/extending-circuitpython.md)
- [Toddler Timer](https://learn.adafruit.com/toddler-timer.md)
- [CircuitPython Powered AT Hand-Raiser](https://learn.adafruit.com/at-hand-raiser.md)
- [OLED TRON Clock](https://learn.adafruit.com/oled-tron-clock.md)
- [Program CircuitPython USB Devices with iPhone & iPad](https://learn.adafruit.com/use-circuitpython-devices-with-iphone-ipad.md)
- [CircuitScheme - Lisp on CircuitPython](https://learn.adafruit.com/scheme-in-circuitpython.md)
- [Generating Text with ChatGPT, Pico W & CircuitPython](https://learn.adafruit.com/generating-text-with-chatgpt-pico-w-circuitpython.md)
- [MIDI Melody Maker](https://learn.adafruit.com/midi-melody-maker.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [A CLI in CircuitPython](https://learn.adafruit.com/a-cli-in-circuitpython.md)
- [CircuitPython 101: Functions](https://learn.adafruit.com/circuitpython-101-functions.md)
- [SSD1306 OLED Displays with Raspberry Pi and BeagleBone Black](https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black.md)
- [Stepper Motor Turntable](https://learn.adafruit.com/stepper-motor-turntable.md)
- [CircuitPython with Jupyter Notebooks](https://learn.adafruit.com/circuitpython-with-jupyter-notebooks.md)
- [A Logger for CircuitPython](https://learn.adafruit.com/a-logger-for-circuitpython.md)
