I ask for help!   hello I wanted to know whether this code is

fastled-samples
gplus
(Rene Muder) #1

I ask for help!
hello I wanted to know whether this code is also on 2 pins can operate? I had already tried it but unfortunately again without success!

#include <Adafruit_NeoPixel.h>

#define PIN 8
#define Pixels 120
#define BG 1

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic ‘v1’ (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel’s data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit…if you must, connect GND first.

int color;
int center = 0;
int step = -1;
int maxSteps = 16;
float fadeRate = 0.6;
int diff;

//background color
uint32_t currentBg = random(256);
uint32_t nextBg = currentBg;

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to ‘off’
}

void loop () {
ripple();
}

void ripple() {
if (BG){
if (currentBg == nextBg) {
nextBg = random(256);
}
else if (nextBg > currentBg) {
currentBg++;
} else {
currentBg–;
}
for(uint16_t l = 0; l < Pixels; l++) {
strip.setPixelColor(l, Wheel(currentBg, 0.1));
}
} else {
for(uint16_t l = 0; l < Pixels; l++) {
strip.setPixelColor(l, 0, 0, 0);
}
}

if (step == -1) {
center = random(Pixels);
color = random(256);
step = 0;
}

if (step == 0) {
strip.setPixelColor(center, Wheel(color, 1));
step ++;
}
else {
if (step < maxSteps) {
strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
strip.setPixelColor(wrap(center - step), Wheel(color, pow(fadeRate, step)));
if (step > 3) {
strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
strip.setPixelColor(wrap(center - step + 3), Wheel(color, pow(fadeRate, step - 2)));
}
step ++;
}
else {
step = -1;
}
}

strip.show();
delay(50);
}

int wrap(int step) {
if(step < 0) return Pixels + step;
if(step > Pixels - 1) return step - Pixels;
return step;
}

// 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, float opacity) {

if(WheelPos < 85) {
return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity);
}
else {
WheelPos -= 170;
return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity);
}
}

(Daniel Garcia) #2

While this group is for the FastLED library, not the Adafruit library, I’ll see what I can do to help you here.

First questions are - what are you building this on? Is it an Arduino Uno or a Trinket or a Gemma?

Second questions are - this code is written to drive leds off of only one pin. What problems did you have when you tried to drive it off of two pins? Did the code fail to compile? Did it fail to run? Did only one of the two strips work? Did neither work?

(Rene Muder) #3

Hello . … the Code ist already. …
M Controller is a arduino Mega … my question : an the Code so Assingned to works AT 2 Pins ! Sorry my englisch ist nod god :frowning: !!!

(Daniel Garcia) #4

What did you try? The code you pasted above is for writing out to one pin, not two. I’d need to see what you tried to tell you why it might not be working.

Also, you say “without success” - but I need to know what that means, again, did it:

  • fail to compile
  • fail to run
  • only work with leds on one pin
  • work with leds on both pins but show the wrong colors

For FastLED, the way you would do this would look like:

#include <FastLED.h>
#define NUM_LEDS 120
#define NUM_STRIPS 2

#define DATA_PIN1 8
#define DATA_PIN2 9

CRGB leds[NUM_LEDS * NUM_STRIPS];

void setup() {
LEDS.addLeds<NEOPIXEL,DATA_PIN1>(leds,NUM_LEDS);
LEDS.addLEds<NEOPIXEL,DATA_PIN2>(leds+NUM_LEDS, NUM_LEDS);
}

void loop() {
for(int i = 0; i < (NUM_LEDS * NUM_STRIPS); i++) {
leds[i] = CRGB::Red;
LEDS.show();
leds[i] = CRGB::Black;
delay(10);
}
}

(Daniel Garcia) #5

Note, again, this g+ group is for the FastLED library - your question is about the Adafruit Neopixel library (and if what I’m describing here isn’t helpful, it may be worth it for you to go to adafruit’s forums - https://forums.adafruit.com/index.php - for help)