#include <Adafruit_NeoPixel.h>

#define PIN_RING   6
#define PIN_MIC    A0
#define PIN_POT    A1
#define NUMLEDS    18
#define OFFSET_MIN 450
#define OFFSET_MAX 500

Adafruit_NeoPixel leds = Adafruit_NeoPixel(NUMLEDS, PIN_RING, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(PIN_MIC, INPUT);
  pinMode(PIN_POT, INPUT);
  leds.begin();
  leds.setBrightness(100);
}

void loop() {
  int intens = analogRead(PIN_MIC);
  int offset = map(analogRead(PIN_POT), 0, 1023, OFFSET_MIN, OFFSET_MAX);

  clear();

  led(intens, offset + 15,   0,   0,   0, 0);
  led(intens, offset + 20,   1,   0, 255, 0);
  led(intens, offset + 20,   2,   0, 255, 0);
  led(intens, offset + 25,   3,  50, 255, 0);
  led(intens, offset + 30,   4, 100, 255, 0);
  led(intens, offset + 35,   5, 120, 255, 0);
  led(intens, offset + 45,   6, 180, 200, 0);
  led(intens, offset + 45,   7, 200, 180, 0);
  led(intens, offset + 50,   8, 200, 150, 0);
  led(intens, offset + 55,   9, 255, 120, 0);
  led(intens, offset + 60,  10, 255, 100, 0);
  led(intens, offset + 65,  11, 255,  80, 0);
  led(intens, offset + 70,  12, 255,  50, 0);
  led(intens, offset + 75,  13, 255,   0, 0);
  led(intens, offset + 80,  14, 255,   0, 0);
  led(intens, offset + 85,  15, 255,   0, 0);
  led(intens, offset + 90,  16, 255,   0, 0);
  led(intens, offset + 100, 17, 255,   0, 0);
}

void led(int intensity, int offset, byte nled, byte r, byte g, byte b) {
  if (intensity > offset) {
    leds.setPixelColor(nled, leds.Color(r, g, b));
    leds.show();
    delay(1);
  }
}

void clear() {
  for (byte x = 0; x < NUMLEDS; x++) {
    leds.setPixelColor(x, leds.Color(0, 0, 0));
  }
}