pxt-calliope/docs/reference/pins/neopixel-matrix-width.md
Juri Wolf 5f7a8e5301
Updates for V4 (#197)
* update yotta defaults for 16kb devices

* refactor deprecated blocks

* updates for button events

* update button events

* update refference

* update docs

* update docs

* update button event blocks

* update docs

* update block id
2022-08-10 09:36:19 -07:00

1.1 KiB

Neopixel matrix width

For Neopixel matrix (strip) on the specified pin, set the width of that matrix. This informs the simulator to display the Neopixel strip as a matrix.

pins.setMatrixWidth(Digital.P1, 16)

Parameters

  • name: The @boardname@ hardware pin to configure (P0-P20)
  • width: a number (for example, from 2 through 16)

Example

To use the example below, you should add the Neopixel extension to your project and then copy the JavaScript code below over to your project. The example creates a strip of 25 neopixels corresponding to a 5x5 matrix and then draws an X on the matrix. Try changing the value of the variable width to get matrices of different sizes.

let width = 5
let strip = neopixel.create(DigitalPin.P1, width * width, NeoPixelMode.RGB)
strip.setMatrixWidth(width)
pins.setMatrixWidth(DigitalPin.P1, width)
for (let i = 0; i <= width - 1; i++) {
    strip.setMatrixColor(i, i, neopixel.colors(NeoPixelColors.Red))
    strip.setMatrixColor(width - (i + 1), i, neopixel.colors(NeoPixelColors.Blue))
}
strip.show()