Hey everyone. I've got about 80 GRB LEDs that I'm controlling with a Nano. I have a simple routine that uses a rotary encoder and interrupts to change the lights from white to soft yellow (my wife is going to use the lights for a studio box).
When I plug the Arduino into my computer via the USB port, it works exactly as expected, however, when I use a 12V adapter through the VIN, all the lights turn an ugly yellow, and are not uniform in color as they are when powered through the USB.
I understand that the recommended voltage range that the Arduino's voltage regulator can handle is 7-12V, so that shouldn't be a problem -- is there anything I'm missing here that would make it act like this?
TIA
Here is the code if needed for reference. It's not very professional, I'm warning you in advance:
#include <Adafruit_NeoPixel.h>
#define PIN 5
#define NUMPIXELS 80
#define BRIGHTNESS 100
#define inputDT 3
#define inputSW 2
#define inputCLK 4
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int brightness = BRIGHTNESS;
unsigned long timesincebutt;
int currentStateCLK;
int previousStateCLK;
int counter =0;
String encdir="";
int red = 255;
int green = 255;
int blue = 255;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP //
/////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// put your setup code here, to run once:
pinMode(inputSW, INPUT_PULLUP);
pinMode(inputCLK, INPUT);
pinMode(inputDT, INPUT);
Serial.begin(9600); // initialize serial communications at 9600 bps
strip.begin();
strip.show();
strip.setBrightness(brightness);
previousStateCLK=digitalRead(inputCLK);
attachInterrupt(digitalPinToInterrupt(inputSW), updateButton, LOW);
attachInterrupt(digitalPinToInterrupt(inputDT), update, CHANGE);
timesincebutt=millis();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP //
/////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
setStrip(red, green, blue);
strip.setBrightness(brightness);
strip.show();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ISR ISR ISR ISR ISR ISR ISR ISR ISR ISR ISR ISR //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void updateButton(){
brightness+=10;
red = 0;
if(brightness > 250){
brightness = 10;
}
}
void update(){
// Interrupt to check on the encoder
currentStateCLK = digitalRead(inputCLK);
if (currentStateCLK != previousStateCLK){
if (digitalRead(inputDT) != currentStateCLK){
// enc would normally be going up, but because of the interrupt pin configuration, up and down are swapped.
// enc is going down
counter--;
encdir="CW";
//What that thang do
if(blue > 5){
blue-=5;
// red-=5;
// green-=5;
}
}else{
//enc is going up
counter++;
encdir="CCW";
//What that thang do
if (blue<250){
blue+=5;
// green+=5;
// red+=5;
}
}
}
previousStateCLK=currentStateCLK;
}
void setStrip(int red, int green, int blue){
//Use red, green, and blue to update every pixel in the strip
for (int i=0;i<NUMPIXELS;i++){
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
return;
}