When working with long strips of NeoPixel, it is quite useful to chunk them into ranges and apply independent colors and animations to them. The range allows to create a new NeoPixel strip instance over a subset of the pixels.

// mount an external Neopixel strip on pin A1 with 24 RGB pixels
let strip = light.createStrip(pins.A1, 24);

// create 2 ranges for each half of the strip
let head = strip.range(0, 12);
let tail = strip.range(12, 12);

Once you have your rangers defined, you can easily apply colors and animation without worrying about complicated index computations.

// turn on 1 pixel on each range
head.setPixelColor(0, Colors.Blue)
tail.setPixelColor(11, Colors.Red)

The example below create 2 ranges and moves the pixels on opposite directions on each of them.

This guide was first published on May 30, 2017. It was last updated on May 30, 2017.

This page (Ranges) was last updated on Sep 27, 2017.

Text editor powered by tinymce.