Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Code created by Chris Evans @drumminhands
- * Used to map a potentiometer to color hue
- *
- */
- // sensor input from http://www.arduino.cc/en/Tutorial/AnalogInput
- // NeoPixels from here: http://learn.adafruit.com/adafruit-neopixel-uberguide/overview
- #include <Adafruit_NeoPixel.h>
- //constansts won't change
- const uint8_t neoPin = 6; // Neopixels Pin
- const uint8_t pxls = 12; // number of pixels in the neopixel ring
- const uint8_t maxBright = 255; // the default brightness between 0 and 255
- // variables that will change
- int sensorPin = A0; // the input pin for the potentiometer
- int sensorValue = 0; // variable to store the value coming from the sensor
- int neoPixelHue = 0; // stores current hue of the neoPixels during the rainbow cycles
- // 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)
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(pxls, neoPin, NEO_GRB + NEO_KHZ800);
- // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
- // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
- // and minimize distance between Arduino and first pixel. Avoid connecting
- // on a live circuit...if you must, connect GND first.
- void setup() {
- strip.begin();
- strip.setBrightness(maxBright); // initialize brightness
- strip.show(); // Initialize all pixels to 'off'
- }
- void loop() {
- sensorValue = analogRead(sensorPin); // read the value from the sensor
- sensorValue = map(sensorValue, 0, 1023, 0, 255); // change value porportionally to be between 0 and 255
- colorSet(Wheel(sensorValue)); // set the color based on the pot
- }
- // sets all pixels to one given color
- void colorSet(uint32_t c){
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, c);
- }
- strip.show();
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- WheelPos = 255 - WheelPos;
- if(WheelPos < 85) {
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- } else if(WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- } else {
- WheelPos -= 170;
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- }
- }
Add Comment
Please, Sign In to add comment