NeoPixel coding problems

Hello,

I'm trying to control some neoPixel strips with a NanoEvery. I got it running with a pot attached but added an RC signal and messed up the code. I added another block of code in the Loop with pulseIn and declared my new pins in setUp. I'm pretty sure the problem is in the Loop. Thinking I need to add brackets, but it compiled so I tried.

Any help welcome.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 5
#define PIN2 6

//  The overall fire brightness
//  (this can affect both color levels and power consumption)
int brightness ; //added for remote control
int brightness2 ;
int rxPin = 9;     
int potPin = A0;

// 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(100, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(2, PIN2, 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.
// For the ultimate NeoPixel guide, check out:
// https://learn.adafruit.com/adafruit-neopixel-uberguide/overview

void setup() {
  strip.begin();
  strip.setBrightness(brightness);
  strip.show(); // Initialize all pixels to 'off'
  pinMode(rxPin, INPUT);    //added for remote control
   strip2.begin();
  strip2.setBrightness(brightness2);
  strip2.show(); // Initialize all pixels to 'off'  
  pinMode(potPin, INPUT);
}

void loop() {
  int temp = pulseIn(rxPin, HIGH);              //added for remote control
  brightness = map(temp, 1000, 1990, 0, 60);   //added for remote control
  strip.setBrightness(brightness);
  
  int temp2 = analogRead(potPin);              //added for remote control
  brightness = map(temp2, 1000, 1990, 0, 60);   //added for remote control
  strip.setBrightness(brightness2);

  

  //  Uncomment one of these RGB (Red, Green, Blue) values to
  //  set the base color of the flame.  The color will flickr
  //  based on the initial base color
  
  //  Regular (orange) flame:
      int r = 50, g = 40, b = 0;

  //  Purple flame:
  //  int r = 158, g = 8, b = 148;

  //  Green flame:
  //int r = 74, g = 150, b = 12;

  //  Flicker, based on our initial RGB values
  for(int i=0; i<strip.numPixels(); i++) {
  int flicker = random(0,55);
  int r1 = r-flicker;
  int g1 = g-flicker;
  int b1 = b-flicker;
  if(g1<0) g1=0;
  if(r1<0) r1=0;
  if(b1<0) b1=0;
  strip.setPixelColor(i,r1,g1, b1);
  }
  strip.show();
  strip2.show();

  //  Adjust the delay here, if you'd like.  Right now, it randomizes the 
  //  color switch delay to give a sense of realism
  delay(random(15,113));
}

I have no idea what is the problem. What does the code actually do? How is that different from what you want?

It doesn't do anything now..

I accidentally had a section commented out // but that didn't change anything when I uncommented it.. I fixed it in the post too just now... the code works fine without the rxPin and pulseIn command and associated lines. It makes the LEDs flicker like a candle. the pot controls the brightness. I want to control a separate pin with two pixels from a remote control and I don't want to run it from a second arduino if I can avoid it. It runs fine like this below..

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 5

//  The overall fire brightness
//  (this can affect both color levels and power consumption)
int brightness ; //added for remote control
int potPin = A0;      //added for remote control

// 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(100, 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.
// For the ultimate NeoPixel guide, check out:
// https://learn.adafruit.com/adafruit-neopixel-uberguide/overview

void setup() {
  strip.begin();
  strip.setBrightness(brightness);
  strip.show(); // Initialize all pixels to 'off'
  pinMode(potPin, INPUT);    //added for remote control
}

void loop() {
  int temp = analogRead(potPin);              //added for remote control
  brightness = map(temp, 0, 1023, 0, 100);   //added for remote control
  strip.setBrightness(brightness);

  //  Uncomment one of these RGB (Red, Green, Blue) values to
  //  set the base color of the flame.  The color will flickr
  //  based on the initial base color
  
  //  Regular (orange) flame:
    int r = 150, g = 150, b = 150;

  //  Purple flame:
  //  int r = 158, g = 8, b = 148;

  //  Green flame:
  //int r = 74, g = 150, b = 12;

  //  Flicker, based on our initial RGB values
  for(int i=0; i<strip.numPixels(); i++) {
    int flicker = random(0,55);
    int r1 = r-flicker;
    int g1 = g-flicker;
    int b1 = b-flicker;
    if(g1<0) g1=0;
    if(r1<0) r1=0;
    if(b1<0) b1=0;
    strip.setPixelColor(i,r1,g1, b1);
  }
  strip.show();

  //  Adjust the delay here, if you'd like.  Right now, it randomizes the 
  //  color switch delay to give a sense of realism
  delay(random(5,13));
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.