Trying to combine Sketches

Hey there everybody! This is my first time working with Arduino, and working with coding.... That being said, I found a couple of example sketches that I would like to combine and I'm really struggling trying to understand what is going wrong in my program. I feel as though it is almost compiled properly, but there is obviously a piece or two that I'm just not understanding. When I try to verify my sketch I'm being told that one of my components in the loop has not been declared in the scope, and I'm not sure where I am supposed to input the code to add the chase to be included in the void loop. If anybody could help me understand what I'm missing, it would be hugely appreciated!!

#include <Adafruit_NeoPixel.h>

#include <FastLED.h>

#define LED_PIN 6

#define DATA_PIN 6

#define LED_COUNT 124

#define NUM_LEDS 124

CRGB leds[NUM_LEDS];

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN);

void setup() {
// put your setup code here, to run once:

strip.begin();
strip.show();
strip.setBrightness(50);
Serial.begin(57600);
Serial.println("resetting");
LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
LEDS.setBrightness(84);
}

void fadeall() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(250);
}
}
void loop() {
// put your main code here, to run repeatedly:
theaterChaseRainbow(35);{

void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for (int a = 0; a < 30; a++) { // Repeat 30 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 increments of 3...
for (int c = b; c < strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
}
static uint8_t hue = 0;
Serial.print("x");
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
Serial.print("x");

// Now go in the other direction.
for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
  // Set the i'th led to red
  leds[i] = CHSV(hue++, 255, 255);
  // Show the leds
  FastLED.show();
  // now that we've shown the leds, reset the i'th led to black
  // leds[i] = CRGB::Black;
  fadeall();
  // Wait a little bit before we loop around and do it again
  delay(10);\

}
}

It might help if that { was a }. Otherwise we need the EXACT error message. In programming details are important.

But really you have function definitions dumped in the middle of what probably should all be code inside loop().

Steve

Let's start with something simple. Can you please modify your original post to ensure the source code is in a single box? It should look like this.

// Your example source code

You need three ' at the beginning and end in the edit window? When you click on this icon </> you get.

```
type or paste code here
```

This ensures we can get all the source code.

Next, format your code in the IDE. Use Tools -> Auto Format
The formatting of the code can give you clues about the structure of the code. If things are misaligned, you know something is wrong. e.g., missing brackets or brackets in the wrong place.

Next, have a look at what scope means.

https://en.cppreference.com/w/cpp/language/scope

Ultrashort, to allow the reuse of variable names they are only valid within the code block that they have been declared in. Scope is like a unit inside a house. It can be a single room/function, the whole house/global variables or even just a closet e.g., a for loop.

It looks like you struggle with the basic stuff. Therefore, I recommend you start with little modification of one sketch until you understand what is going on. That will allow you to integrate other stuff much easier.

TL;DR: post both original sketches unaltered as you found them using code tags.

You'll be better off understanding what each sketch is doing, and rewriting them.


You are using two different libraries
#include <Adafruit_NeoPixel.h> and

#include <FastLED.h>

which are addressing 124 LEDs

#define LED_COUNT 124 and 

#define NUM_LEDS 124

on the same pin

#define LED_PIN 6 and

#define DATA_PIN 6

with each an object to control them

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN); and

LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);

this may or may not work. I would try to convert one of the sketches to use the library used in the other; those two libraries have very similar functions, which you go with will be clearer when you have posted the two original sketches as yo found them.

Combining may be easy, it might be a real challenge. I like the idea of getting both two work using the same library as a starter. Separate but more equal.

HTH

a7