I need help with my project. I'm trying to build a LED strip setup with three connected strips. I want to be able to control the lights with button pushes. Everything worked fine when testing with an arduino on a breadboard, with only one button connected. After soldering everything I get power, but the buttons are not working. I have connected all power and ground wires from the buttons together, and soldered them to the 5V and GND on the back of the trinket. The buttons also have extra ground wires that go to pin 9 and 10 on the trinket. The data wires from two of the LED strips are connected to pin 5 and the third strip is connected to pin 7.
The parts I am using:
Itsy Bitsy 32u4 5V
Trinket Pro Backpack
4400mAh Lipo battery
One slide switch to turn off power
Two push switches connected to 10K ohm resistors
Three NeoPixel Led strips
3-pin Jumper cables
Here is my code:
- Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
//Button Pins
#define BUTTON_PIN 9
#define BUTTON_PIN2 10
//LED Strip Pins
#define PIXEL_PIN 5
#define PIXEL_PIN2 7
#define PIXEL_COUNT 30
#define PIXEL_COUNT2 30
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_RGBW + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(PIXEL_COUNT2, PIXEL_PIN2, NEO_RGBW + NEO_KHZ800);
const int buttonPin = 3;
bool onAndOff = false;
int buttonState = 0;
const int buttonPin2 = 4;
bool onAndOff2 = false;
int buttonState2 = 0;
void setup()
{
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip2.begin();
for(uint16_t i = 0; i < strip2.numPixels(); i++) {
strip2.setPixelColor(i, 255, 100, 0);
}
strip2.show(); // Initialize all pixels to 'off'
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
pinMode(buttonPin2, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if (buttonState == HIGH)
{
if (onAndOff == false)
{
onAndOff = true;
rainbowCycle(20);
}
else
{
onAndOff = false;
colorWipe(strip.Color(0, 0, 255), 0); // Blue
}
}
else
if (buttonState2 == HIGH)
{
if (onAndOff2 == false)
{
onAndOff2 = true;
colorWipe(strip.Color(0, 0, 0, 255), 0); // White
}
else
{
onAndOff2 = false;
brighten ();
darken ();
}
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void brighten() {
uint16_t i, j;
for (j = 20; j < 200; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, j/2, 0);
}
strip.show();
delay (1);
}
//delay (1500);
}
void darken() {
Serial.begin(9600);
uint16_t i, j;
for (j = 200; j > 20; j--) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, j/2, 0);
}
strip.show();
// delay (10);
Serial.println(j);
}
delay(1);
}
I appreciate any help. Thank you.
Svend