A Neo-Pixel package for pxt-microbit
Перейти к файлу
Sarah Rietkerk 9ef28dd8ec
Merge pull request #67 from microsoft/srietkerk-patch
Bumping to 0.7.6
2023-06-13 13:54:59 -07:00
.github/workflows Create makecode.yml 2020-05-21 11:30:23 -07:00
.vscode Bumping verstion to 0.7.4 2022-12-08 15:11:12 -08:00
_locales Update _locales/es-ES/neopixel-strings.json 2022-12-08 14:47:59 -08:00
.gitattributes adding missing .gitattributes file 2016-08-30 21:20:14 -07:00
.gitignore ignore projects 2017-12-14 08:48:54 -08:00
LICENSE.txt Import from pxt-microbit 2016-07-26 17:55:13 +01:00
README.md Update README.md 2020-05-21 11:30:57 -07:00
SECURITY.md Microsoft mandatory file (#62) 2022-09-22 17:16:12 -07:00
icon.png New thumbnail art 2023-06-13 13:24:18 -07:00
neopixel.ts revert use of setBufferMode 2020-05-21 11:43:30 -07:00
neotest.ts setmode (#52) 2020-05-21 11:39:32 -07:00
pxt.json Bumping to 0.7.6 2023-06-13 13:52:26 -07:00
tsconfig.json Import from pxt-microbit 2016-07-26 17:55:13 +01:00

README.md

NeoPixel driver

This library provides a driver for various Neo Pixel LED strips, see https://www.adafruit.com/category/168.

NeoPixels consist of programmable RGB LEDs (WS2812B), every one of them controlled separately.

~ hint

See Microsoft/pxt-ws2812b for basic WS2812B led support.

~

Basic usage

// Create a NeoPixel driver - specify the pin, number of LEDs, and the type of 
// the NeoPixel srip, either standard RGB (with GRB or RGB format) or RGB+White.
let strip = neopixel.create(DigitalPin.P0, 24, NeoPixelMode.RGB);

// set pixel colors
strip.setPixelColor(0, NeoPixelColors.White); // white
strip.setPixelColor(1, 0xff0000);     // red
strip.setPixelColor(2, 0x00ff00);     // green
strip.setPixelColor(3, NeoPixelColors.Blue);    // blue

// send the data to the strip
strip.show()

Use ||setBrightness|| to lower the brightness (it's maxed out by default).

Use ||shift|| or ||rotate|| to shift the lights around.

Use ||setPixelWhiteLED|| to set brightness of the white pixel for RGB+W strips.

HSL color format

Use neopixel.hslToRgb() to create colors using hue, saturation, and lightness.

Example: Using accelerometer to control colors

This little program will let the position of the microbit control the color of the first LED. This first LED will then get shifted further away every 100ms.

let strip = neopixel.create(DigitalPin.P0, 24, NeoPixelMode.RGB_RGB)
while (true) {
    let x = input.acceleration(Dimension.X) / 2;
    let y = input.acceleration(Dimension.Y) / 2;
    let z = input.acceleration(Dimension.Z) / 2;
    strip.shift(1);
    strip.setPixelColor(0, neopixel.rgb(x, y, -z));
    strip.show();
    basic.pause(100);
}

Supported targets

  • for PXT/microbit
  • for PXT/calliope

License

MIT

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.