Components and supplies
10 10K trimmer
Arduino UNO
WS2811 Addressable LED strip (1m, 60 LEDs)
Project description
Code
Code snippet #1
arduino
1/* 2Color addressable LEDs control using Adafruit NeoPixel library 3 4 5 Parts required: 6 1m strip of addressable LEDs http://store.arduino.cc/products/C000083 7 8 9 This example code is part of the public domain 10 */ 11 12#include <Adafruit_NeoPixel.h> 13 14const 15 int NUMPIXELS = 60; //number of LEDs in 1m 16const int LEDsPin = 9; // LEDs 17 connected to digital pin 9 18 19const int redPotPin = A0; // pin to control 20 red 21const int greenPotPin = A1; // pin to control green 22const int bluePotPin 23 = A2; // pin to control blue 24 25int redValue = 0; // value to write to the 26 red LED 27int greenValue = 0; // value to write to the green LED 28int blueValue 29 = 0; // value to write to the blue LED 30 31int redPotValue = 0; // variable to 32 hold the value from the red pot 33int greenPotValue = 0; // variable to hold the 34 value from the green pot 35int bluePotValue = 0; // variable to hold the value 36 from the blue pot 37 38// When we setup the NeoPixel library, we tell it how many 39 pixels, and which pin to use to send signals. 40Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, 41 PIN, NEO_GRB + NEO_KHZ800); 42 43void setup() { 44 // initialize serial communications 45 at 9600 bps: 46 Serial.begin(9600); 47 48 // set the digital pin as output 49 50 pinMode(LEDsPin, OUTPUT); 51} 52 53void loop() { 54 // Read the pots first: 55 56 57 // read the value from the red pot control: 58 redPotValue = analogRead(redPotPin); 59 60 // give the ADC a moment to settle 61 delay(5); 62 // read the value from 63 the green pot control: 64 greenPotValue = analogRead(greenPotPin); 65 // give 66 the ADC a moment to settle 67 delay(5); 68 // read the value from the blue pot 69 control: 70 bluePotValue = analogRead(bluePotPin); 71 72 // print out the values 73 to the serial monitor 74 Serial.print("raw sensor Values \ red: "); 75 Serial.print(redPotValue); 76 77 Serial.print("\ green: "); 78 Serial.print(greenPotValue); 79 Serial.print("\ 80 Blue: "); 81 Serial.println(bluePotValue); 82 83 /* 84 In order to use the 85 values from the pots for the LEDs, 86 you need to do some math. The ADC provides 87 a 10-bit number, 88 but analogWrite() uses 8 bits. You'll want to divide your 89 90 sensor readings by 4 to keep them in range of the output. 91 */ 92 redValue 93 = map(redPotValue, 0, 1023, 0, 255); 94 greenValue = map(greenPotValue, 0, 1023, 95 0, 255); 96 blueValue = map(bluePotValue, 0, 1023, 0, 255);; 97 98 // print 99 out the mapped values 100 Serial.print("Mapped sensor Values \ red: "); 101 102 Serial.print(redValue); 103 Serial.print("\ green: "); 104 Serial.print(greenValue); 105 106 Serial.print("\ Blue: "); 107 Serial.println(blueValue); 108 109 // For 110 a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count 111 of pixels minus one. 112 for (int i = 0; i < NUMPIXELS; i++) { 113 // pixels.Color 114 takes RGB values, from 0,0,0 up to 255,255,255 115 pixels.setPixelColor(i, pixels.Color(redValue, 116 greenValue, blueValue)); 117 pixels.show(); // This sends the updated pixel color 118 to the hardware. 119 delay(50); // Delay for a period of time (in milliseconds). 120 121 } 122}
Code snippet #1
arduino
1/* 2Color addressable LEDs control using Adafruit NeoPixel library 3 4 Parts required: 5 1m strip of addressable LEDs http://store.arduino.cc/products/C000083 6 7 This example code is part of the public domain 8 */ 9 10#include <Adafruit_NeoPixel.h> 11 12const int NUMPIXELS = 60; //number of LEDs in 1m 13const int LEDsPin = 9; // LEDs connected to digital pin 9 14 15const int redPotPin = A0; // pin to control red 16const int greenPotPin = A1; // pin to control green 17const int bluePotPin = A2; // pin to control blue 18 19int redValue = 0; // value to write to the red LED 20int greenValue = 0; // value to write to the green LED 21int blueValue = 0; // value to write to the blue LED 22 23int redPotValue = 0; // variable to hold the value from the red pot 24int greenPotValue = 0; // variable to hold the value from the green pot 25int bluePotValue = 0; // variable to hold the value from the blue pot 26 27// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 28Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 29 30void setup() { 31 // initialize serial communications at 9600 bps: 32 Serial.begin(9600); 33 34 // set the digital pin as output 35 pinMode(LEDsPin, OUTPUT); 36} 37 38void loop() { 39 // Read the pots first: 40 41 // read the value from the red pot control: 42 redPotValue = analogRead(redPotPin); 43 // give the ADC a moment to settle 44 delay(5); 45 // read the value from the green pot control: 46 greenPotValue = analogRead(greenPotPin); 47 // give the ADC a moment to settle 48 delay(5); 49 // read the value from the blue pot control: 50 bluePotValue = analogRead(bluePotPin); 51 52 // print out the values to the serial monitor 53 Serial.print("raw sensor Values \ red: "); 54 Serial.print(redPotValue); 55 Serial.print("\ green: "); 56 Serial.print(greenPotValue); 57 Serial.print("\ Blue: "); 58 Serial.println(bluePotValue); 59 60 /* 61 In order to use the values from the pots for the LEDs, 62 you need to do some math. The ADC provides a 10-bit number, 63 but analogWrite() uses 8 bits. You'll want to divide your 64 sensor readings by 4 to keep them in range of the output. 65 */ 66 redValue = map(redPotValue, 0, 1023, 0, 255); 67 greenValue = map(greenPotValue, 0, 1023, 0, 255); 68 blueValue = map(bluePotValue, 0, 1023, 0, 255);; 69 70 // print out the mapped values 71 Serial.print("Mapped sensor Values \ red: "); 72 Serial.print(redValue); 73 Serial.print("\ green: "); 74 Serial.print(greenValue); 75 Serial.print("\ Blue: "); 76 Serial.println(blueValue); 77 78 // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. 79 for (int i = 0; i < NUMPIXELS; i++) { 80 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 81 pixels.setPixelColor(i, pixels.Color(redValue, greenValue, blueValue)); 82 pixels.show(); // This sends the updated pixel color to the hardware. 83 delay(50); // Delay for a period of time (in milliseconds). 84 } 85}
Downloadable files
Schematic 1
Schematic 1
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
7
1
Anonymous user
7 years ago
Did anyone have a problem with data interruption between the colors? Sometimes I would get a random spike in a color when the POT wasn't even on. Any ideas?