项目作者: microsoft

项目描述 :
A Neo-Pixel package for pxt-microbit
高级语言: TypeScript
项目地址: git://github.com/microsoft/pxt-neopixel.git
创建时间: 2016-07-26T16:31:59Z
项目社区:https://github.com/microsoft/pxt-neopixel

开源协议:MIT License

下载


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

  1. // Create a NeoPixel driver - specify the pin, number of LEDs, and the type of
  2. // the NeoPixel srip, either standard RGB (with GRB or RGB format) or RGB+White.
  3. let strip = neopixel.create(DigitalPin.P0, 24, NeoPixelMode.RGB);
  4. // set pixel colors
  5. strip.setPixelColor(0, NeoPixelColors.White); // white
  6. strip.setPixelColor(1, 0xff0000); // red
  7. strip.setPixelColor(2, 0x00ff00); // green
  8. strip.setPixelColor(3, NeoPixelColors.Blue); // blue
  9. // send the data to the strip
  10. 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.

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

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.