Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | Page 18
Color Mixing LEDs
#include
5V const int NUMPIXELS = 30; const
int LEDsPin = 9;
const int redPotPin = A0;
const int greenPotPin = A1;
const int bluePotPin = A2;
GRD int redValue = 0;
int greenValue = 0;
int blueValue = 0;
330 ohm
int redPotValue = 0;
int greenPotValue = 0;
int bluePotValue = 0;
Adafruit_NeoPixel pixels =
Adafruit_NeoPixel(NUMPIXELS,
LEDsPin, NEO_RGB + NEO_
KHZ800);
void setup() {
Serial.begin(9600);
pinMode(LEDsPin, OUTPUT);
}
•
•
•
•
•
•
12.5mm wide, 4mm thick with casing on, 33mm long
per segment
30 LEDs per meter
Removable IP65 weatherproof casing
Maximum 5V @ 60mA draw per 1.3” strip segment
5VDC power requirement
integrated RGB LEDs per segment, individually
controllable
void loop() {
redPotValue =
analogRead(redPotPin);
delay(5);
greenPotValue =
analogRead(greenPotPin);
delay(5);
bluePotValue =
analogRead(bluePotPin);
Serial.print(“raw sensor Values \t
red: “);
Serial.print(redPotValue);
Serial.print(“\t green: “);
Serial.print(greenPotValue);
Serial.print(“\t Blue: “);
Serial.println(bluePotValue);
redValue = map(redPotValue, 0,
1023, 0, 255);
greenValue =
map(greenPotValue, 0, 1023, 0,
255);
blueValue = map(bluePotValue, 0,
1023, 0, 255);;
Serial.print(“Mapped sensor
Values \t red: “);
Serial.print(redValue);
Serial.print(“\t green: “);
Serial.print(greenValue);
Serial.print(“\t Blue: “);
Serial.println(blueValue);
for (int i = 0; i < NUMPIXELS;
i++) {
pixels.setPixelColor(i, pixels.
Color(redValue, greenValue,
blueValue));
pixels.show();
delay(50);
}
}
WS2812