The code is written in the Arduino IDE and uses the NeoPixel library. After the pins are defined, the analog values produced by the potentiometer are mapped to digital values. This is then plugged in as the value for the amount of white light being produced by the RGBW NeoPixel ring. The RGB values are left at zero to avoid any blue tinted light. This allows you to control the “brightness” of the NeoPixels without messing with the brightness parameter in the NeoPixel library which is not meant to be changed after the initial definition in the code setup.
// SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 0 //neopixel pin int POT = A1; //analog pin 1 = Trinket m0 Pin 2 int val = 0; // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel ring = Adafruit_NeoPixel(16, PIN, NEO_RGBW + NEO_KHZ800); void setup() { ring.begin(); ring.setBrightness(255); //max brightness available for the pot ring.show(); // Initialize all pixels to 'off' } void loop() { val = analogRead(POT); //will hold analog value sent by pot val = map(val, 0, 1023, 0, 255); //maps analog values to digital so that it can be used by the neopixel uint16_t i; //sets all 16 pixels to on and only show level of white light defined by analog value of the pot for (i = 0; i < ring.numPixels(); i++) { ring.setPixelColor(i, 0, 0, 0, val); } ring.show(); }
Page last edited January 21, 2025
Text editor powered by tinymce.