Pass a Strip to a function
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Adam_Rich
- Posts: 2
- Joined: Tue Oct 12, 2021 8:00 pm
Pass a Strip to a function
Hello, i was working on limiting my code and as I have multiple different NeoPixel objects I want to be able to pass them through the same function and specify what strip gets affected by the function. Is this possible?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Pass a Strip to a function
Yes it is. You can pass the address of the strip object as a parameter.
https://www.learncpp.com/cpp-tutorial/p ... y-address/
https://www.learncpp.com/cpp-tutorial/p ... y-address/
- Adam_Rich
- Posts: 2
- Joined: Tue Oct 12, 2021 8:00 pm
Re: Pass a Strip to a function
ok so i tried that and it will run the first-time but wont loop can you tell what I'm doing wrong?
Code: Select all
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define UL_LED_PIN 6
#define UL_LED_COUNT 60
#define FL_LED_PIN 7
#define FL_LED_COUNT 24
//DECLARE RING OBJECT
Adafruit_NeoPixel upLight(UL_LED_COUNT, UL_LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel FairyLight(FL_LED_COUNT, FL_LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
upLight.begin();
upLight.show();
upLight.setBrightness(50); // To be moved when DMX Functionality is added
FairyLight.begin();
FairyLight.show();
FairyLight.setBrightness(50); // To be moved when DMX Functionality is added
}
void loop() {
Serial.println("Loop Started");
// put your main code here, to run repeatedly:
theaterChase(upLight, upLight.Color(127,127,127), 5, 50);
Serial.println("Loop Finished");
}
void theaterChase(Adafruit_NeoPixel light, uint32_t color, int wait, int brightness) {
light.setBrightness(brightness);
for(int a=0; a<10; a++) {
Serial.println("Loop A");
for(int b=0; b<3; b++) {
light.clear();
Serial.println("Loop B");
for(int c=b; c<light.numPixels(); c += 3) {
Serial.println("Loop C");
light.setPixelColor(c, color);
}
light.show();
delay(wait);
}
}
}
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: Pass a Strip to a function
Looks like you are passing the whole strip instead of just the address as suggested.
Please be positive and constructive with your questions and comments.