/pxt-oled

MakeCode extension for controlling SSD1306 OLED display 128×64 using BBC micro:bit.

Primary LanguageTypeScriptOtherNOASSERTION

Extension for control SSD1306 OLED display 128×64.

Blocks

color argument is the color of pixel on the OLED display. The true means that the pixel will be on, false means that the pixel will be off.

x and y arguments are the x and y positions. Point 0,0 is in the upper left corner of the display. The display is 128 pixels wide (x) and 64 pixels high (y). This means that x can be from 0 to 127 and y can be from 0 to 63.

toggle argument sets whether pixel inversion is used instead of pixel redrawing.

oled.init()

Initalize OLED display connected at address 60 (0x3C) on I2C. Must be called when the program starts.

oled.setContrast(255)

Sets contrast of display (0 to 255).

oled.clear(false)

Fills the display with color.

oled.draw()

Sends data to the OLED display. You have to call it whenever you want to update the display.

oled.setPx(0, 0, true)

Sets the pixel color at position x y to color.

oled.togglePx(0, 0)

Toggles the pixel color at position x y.

oled.px(0, 0)

Returns the pixel color at position x y.

oled.drawText("text", 0, 0, true, false)

Draws the text text, which has the upper left corner at position x y. The color of the text is determined by color.

oled.drawRect(0, 0, 10, 10, true, false, false)

Draws a rectangle with the upper left vertex at position x1 y1 and the lower right vertex at position x2 y2. The fill option specifies whether the rectangle will be filled with the color color. If false, then only the outline is drawn.

oled.drawLine(0, 0, 10, 10, true, false)

Draws a line from position x1 y1 to position x2 y2.

oled.drawImage(images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`), 0, 0, true, false, false)

Show image of type Image at position x y. Fields filled in white in the image are drawn in color on the OLED display. The background determines whether fields that are not filled with white are also drawn. You can add image from the Images category or import Imageio library: https://github.com/Pythom1234/pxt-imageio

oled.addChar(oled.charImage(`
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
`), "c")

oled.addChar: Add character char for function oled.drawText(). The character is specified by image. oled.charImage: Make image for oled.addChar(). It's 8 pixels wide and 10 pixels high.

Examples

I also made a extension that uses OLED display (it's is still in development): https://github.com/Pythom1234/pxt-games

License

MIT

Supported targets

  • for PXT/microbit
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>