|
4 | 4 | # Basic example of clearing and drawing pixels on a SSD1306 OLED display.
|
5 | 5 | # This example and library is meant to work with Adafruit CircuitPython API.
|
6 | 6 |
|
7 |
| -# Import all board pins. |
8 |
| -from board import SCL, SDA |
9 |
| -import busio |
10 |
| - |
11 |
| -# Import the SSD1306 module. |
| 7 | +import board |
| 8 | +import displayio |
12 | 9 | import adafruit_ssd1306
|
13 | 10 |
|
| 11 | +displayio.release_displays() |
14 | 12 |
|
15 |
| -# Create the I2C interface. |
16 |
| -i2c = busio.I2C(SCL, SDA) |
| 13 | +# Create the I2C bus interface. |
| 14 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 15 | +# i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040 |
17 | 16 |
|
18 | 17 | # Create the SSD1306 OLED class.
|
19 |
| -# The first two parameters are the pixel width and pixel height. Change these |
20 |
| -# to the right size for your display! |
21 |
| -display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) |
22 |
| -# Alternatively you can change the I2C address of the device with an addr parameter: |
23 |
| -# display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31) |
| 18 | +display_width = 128 |
| 19 | +display_height = 32 |
| 20 | +display = adafruit_ssd1306.SSD1306_I2C(display_width, display_height, i2c) |
| 21 | +# You can change the I2C address with an addr parameter: |
| 22 | +# display = adafruit_ssd1306.SSD1306_I2C(display_width, display_height, i2c, addr=0x31) |
24 | 23 |
|
25 |
| -# Clear the display. Always call show after changing pixels to make the display |
26 |
| -# update visible! |
| 24 | +# fills display with black pixels clearing it |
27 | 25 | display.fill(0)
|
28 | 26 | display.show()
|
29 | 27 |
|
|
0 commit comments