Now let's take the analog value and do something fun with it. How about turning on the NeoPixels to represent knob position? Like all NeoPixels off is one direction, and all NeoPixels on is the other direction.

We can do this pretty easy using the map function. We know the range of values we expect from the analog input, 0-1023, and we just want to map that to how many NeoPixels to light up, 0-10. So, it's just a matter of coding it up.

And here it is.

// Circuit Playground Analog In - NeoPixel Fun
// Author: Carter Nelson
// MIT License (

#include <Adafruit_CircuitPlayground.h>

uint16_t value;
uint8_t pixels;

void setup() {

void loop() {
  value = analogRead(10);
  pixels = map(value, 0, 1023, 0, 10);

  for (int p=0; p<pixels; p++) {
    CircuitPlayground.setPixelColor(p, 0xFF00FF);

With this code loaded and running on the Circuit Playground, try turning the knob. You should see the NeoPixels light up in accordance with the knob position.

This guide was first published on Feb 11, 2017. It was last updated on Feb 11, 2017.

This page (NeoPixel Fun) was last updated on Feb 08, 2017.

Text editor powered by tinymce.