0

Arduino trinket pro 5V. Control a second LED strip separatel
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino trinket pro 5V. Control a second LED strip separatel

by Majus431 on Sun Sep 19, 2021 7:46 am

Dear Sir or Madam,

With the help of the Arduino Pro Trinket 5V and the Powerboost 1000C I put together a circuit to control an Adafruit_NeoPixel strip.

As you can see in the attached script, I can switch between 2 different modes using the switch on the Trinket.

Strip 1:
1 modes: colorWipe (strip.Color (255, 0, 0), 50); // Red
2 modes: FadeInOut (0xff, 0x00, 0x00);


Now I would like to add a second strip, also with a push button and used separately from each other:


Strip 1:
1 modes: colorWipe (strip.Color (255, 0, 0), 50); // Red
2 modes: FadeInOut (0xff, 0x00, 0x00);

Strip 2:
1 modes: colorWipe (strip.Color (255, 0, 0), 50); // Red
2 modes: theaterChase;

Is this possible? If so, how does the circuit have to be supplemented in the circuit diagram?
And what has to be added in the script.

thanks in advance for all possible tips

Majus431



The Script:



#include <Adafruit_NeoPixel.h>
#include "FastLED.h"
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];

#define LED_PIN 6


#define PIN 6

#define LED_COUNT 60

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);


// constants won't change. They're used here to set pin numbers:
const int buttonPin = 3; // the number of the pushbutton pin

const int ledPin = 6; // the number of the LED pin



// variables will change:
int buttonState = 0; // variable for reading the pushbutton status


void setup() {
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.

strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

}

void loop() {



// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
colorWipe(strip.Color(255, 0, 0), 50); // Red
} else {
FadeInOut(0xff, 0x00, 0x00);
}




}





void FadeInOut(byte red, byte green, byte blue){
float r, g, b;

for(int k = 0; k < 256; k=k+1) { //original: for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red; // r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);

}

for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);

}
}

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}





void colorWipe(uint32_t color, int wait) { //void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment delay(wait);
}
}



void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
Attachments
Schaltbild1.PNG
Arduino trinket pro 5V. Control a second LED strip separately, possible?
Schaltbild1.PNG (233.5 KiB) Viewed 43 times

Majus431
 
Posts: 1
Joined: Sun Sep 19, 2021 7:33 am

Re: Arduino trinket pro 5V. Control a second LED strip separ

by adafruit_support_bill on Sun Sep 19, 2021 8:10 am

There is tutorial on the subject here: https://learn.adafruit.com/multi-taskin ... for-a-spin

adafruit_support_bill
 
Posts: 82121
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.