So, I have a fairly complicated setup, and it's producing two issues that make me a little nervous, so I wanted to run them by you.
Setup: I've made a replica of the Stygian Blade from Hades. There are two strips of 25 lights on the inside rim, and two strips of 45 lights on the outside rim, for a total of 140 NeoPixels (maybe you see where this is going). They are controlled by an ItsyBitsy 32u4 5v. Power comes from a LiPo 3.7V 2000mAh battery that is running into a PowerBoost 1000 Basic - 5V USB Boost @ 1000mA from 1.8V+. The outside strips get their power directly from the PowerBoost (the 5V and GND pins), while the inside strips get their power from the ItsyBitsy (the 5V and GND pins), which in turn gets it's power from the PowerBoost (the + and - output where the USB connector would typically go, since I'm not using that connection). Additionally, there is a switch hooked up to another small board with two resistors and a wire running to GND on the ItsyBitsy that has wires to Pins 2 & 4 to act as switch controls. Finally, the LEDs are controlled by Pins 6 & 8. What this all does is give me a switch with three positions: one turns off the lights, one turns all the lights on (green inside, white outside), and one animates the lights (two different animations, inside and outside). It's pretty cool.
Having typed all that out, I realize that it would probably be a lot easier to try to diagram all this. So I guess my first question is, are there any easy pieces of software to diagram connections like this? I'm a noob. Forgive me.
The Code: See bottom of this post.
Question 1: The first concerning thing is that when the lights are in the All On position there is a quiet but discernable hiss coming from either the ItsyBitsy or the PowerBoost. When the lights are in the Animation position, that hiss is noticeable too, but only during the part of the animation when the lights are brightest. So, is this a sign of something dangerous? Am I drawing too much power through this system? Should I ignore it?
Question 2: This is a bigger deal. Sometimes, this system runs just great for 10 or 20 or 30 minutes. And sometimes it stops suddenly after just a few minutes. In that instance, if I unplug the battery from the PowerBoost and reconnect it, it typically starts back up again, but that seems like a thing I should try to figure out what it's happening.
Ok. So thats where I am. Again, please forgive me, I'm very new to all of this, and have likely made a lot of mistakes. I will be grateful for any guidance you can give!
Code: Select all
#include <Adafruit_NeoPixel.h>
int brightness=0;
int fadeAmount=10; // 25 gives 8 per cycle, 20 9, etc
Adafruit_NeoPixel stripIN(25, 6, NEO_GRB + NEO_KHZ800);
//LED_COUNT, LED_PIN, Gobbledygook
Adafruit_NeoPixel stripOUT(45, 8, NEO_GRB + NEO_KHZ800);
//LED_COUNT, LED_PIN, Gobbledygook
const int buttonAPin = 2; // the number of the pushbutton pin
int buttonAState = 0; // variable for reading the pushbutton status
const int buttonBPin = 4; // the number of the pushbutton pin
int buttonBState = 0; // variable for reading the pushbutton status
// the setup routine runs once when you press reset:
void setup() {
stripIN.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
stripIN.show(); // Turn OFF all pixels ASAP
stripOUT.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
stripOUT.show(); // Turn OFF all pixels ASAP
pinMode(buttonAPin, INPUT);
pinMode(buttonBPin, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
buttonAState = digitalRead(buttonAPin);
buttonBState = digitalRead(buttonBPin);
if (buttonAState == HIGH) {
colorWipeIN(stripIN.Color(0, 255, 0), 50);
colorWipeOUT(stripOUT.Color(255, 153, 153), 50);
} else
{
if (buttonBState == HIGH)
{
meteorRain(0,255,0,10, 64, true, 10);
stripOUT.setBrightness(brightness);
colorWipeOUT(stripOUT.Color(255,255,153),0);
brightness=brightness+fadeAmount;
if(brightness<=0||brightness>=100)
{fadeAmount=-fadeAmount;}
}
else {
colorWipeIN(stripIN.Color(0, 0, 0), 0);
colorWipeOUT(stripOUT.Color(0, 0, 0), 0);
}
}
}
//STRIP IN FUNCTIONS
// Fill the dots one after the other with a color
void colorWipeIN(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<stripIN.numPixels(); i++) {
stripIN.setPixelColor(i, c);
stripIN.show();
}
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);
for(int i = 0; i < 25+25; i++) {
// fade brightness all LEDs one step
for(int j=0; j<25; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <25) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = stripIN.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
stripIN.setPixelColor(ledNo, r,g,b);
}
void showStrip() {
stripIN.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
stripIN.setPixelColor(Pixel, stripIN.Color(red, green, blue));
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < 25; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
//STRIP OUT FUNCTIONS
// Fill the dots one after the other with a color
void colorWipeOUT(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<stripOUT.numPixels(); i++) {
stripOUT.setPixelColor(i, c);
stripOUT.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 stripOUT.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return stripOUT.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return stripOUT.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}