/ Textile_Potentiometer_Hoodie / Textile_Potentiometer_Hoodie.ino
Textile_Potentiometer_Hoodie.ino
1 // SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include <Adafruit_NeoPixel.h> 6 7 #define PIN 1 8 // Parameter 1 = number of pixels in strip 9 // Parameter 2 = Arduino pin number (most are valid) 10 // Parameter 3 = pixel type flags, add together as needed: 11 // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 12 // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 13 // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 14 // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 15 Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800); 16 17 int sensorPin = 1; // select the input pin for the potentiometer (analog 1 is digital 2) 18 int sensorValue = 0; // variable to store the value coming from the sensor 19 int colorValue = 0; 20 21 void setup() { 22 // Set internal pullup resistor for sensor pin (analog 1 is digital 2) 23 pinMode(2, INPUT_PULLUP); 24 strip.begin(); 25 strip.setBrightness(40); //adjust brightness here 26 strip.show(); // Initialize all pixels to 'off' 27 } 28 29 void loop() { 30 // read the value from the sensor: 31 sensorValue = analogRead(sensorPin); 32 colorValue = map(sensorValue, 0, 1024, 0, 255); //map sensor values from 0-124 to 0-255 33 for (int i = 0; i<strip.numPixels(); i++){ 34 strip.setPixelColor(i, Wheel(colorValue)); //use Wheel function to set color 35 } 36 strip.show(); 37 } 38 39 // Input a value 0 to 255 to get a color value. 40 // The colours are a transition r - g - b - back to r. 41 uint32_t Wheel(byte WheelPos) { 42 if(WheelPos < 85) { 43 return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); 44 } else if(WheelPos < 170) { 45 WheelPos -= 85; 46 return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); 47 } else { 48 WheelPos -= 170; 49 return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); 50 } 51 }