Combine 3 Neopixel Sketches together

I am a complete noob when it comes to coding and sketching. I do highly detailed models, and do lighting in them. Up until now, it's typically been just pre-wired 9v LEDs, 3v SMD LEDs and at times combined with fiber optics.

But I have a new model I'm working on where I want some action in the engine. So I have a Trinket with a single neopixel LED and I've created 3 sketches that on their own all work just fine. Sketch 1- fade from 0 to full yellow brightness. Sketch 2- fade from yellow to red. Sketch 3- flicker red. So I want to combine these into a single sketch where the engine warms up yellow, heats up to red and then flickers. But I cannot figure out how to combine the sketches together to make it a single action.

I also don't know how to present my sketches here for help. Do I upload the .ino file? Or do I copy and paste the sketch? Sorry for the ignorance. Never touched any of this before.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

OK. Don't know how to draw a circuit. Here's a photo of my setup. Just a single neopixel, gnd to gnd on Trinket, postive to 3v on Trinket, and pin 1 to the data input on the neopixel.

20171105_170344 by Christopher Olson, on Flickr

And here are my 3 sketches. Again, I want sketch 1 to run and when done go to 2, then 2 go to 3. And 3 would then run infinitely.

Sketch 1

// Simple yellow brightness fade up from 0 to full
// (c) 2017 Christopher Olson

#include <Adafruit_NeoPixel.h>

// Which pin on Trinket is connected to the Neopixel
#define PIN 1

// Parameter 1 = number of pixels
// Parameter 2 = Trinket pin number 
// Parameter 3 = pixel type flags, add together as needed:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.setPixelColor(0, 255, 255, 0); // pixel color set to yellow
  strip.begin();
  strip.show();
}

void loop() 
  {
  for (int i = 1; i <255; ++i){
    strip.setBrightness(0+i); // brings up brightness from 0 to full
    strip.show();
    delay (40); // speed of brightness adjustment
  }
}

Sketch 2

// Simple yellow to red color fade
// (c) 2017 Christopher Olson
   
#include <Adafruit_NeoPixel.h>

// Which pin on Trinket is connected to the Neopixel
#define PIN 1

// Parameter 1 = number of pixels
// Parameter 2 = Trinket pin number 
// Parameter 3 = pixel type flags, add together as needed:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.setPixelColor(0, 255, 255, 0); // pixel color set to yellow
  strip.begin();
  strip.show();
}

void loop() {
  for (int i = 255; i >0; --i){
    strip.setPixelColor(0, 255, i, 0); // fades pixel color from yellow to red
    strip.show();
    delay(25); // speed of color fade
  }
 }

Sketch 3

// Simple red flicker effect
// (c) 2017 Christopher Olson

#include <Adafruit_NeoPixel.h>

// Which pin on Trinket is connected to the Neopixel
#define PIN 1

// Parameter 1 = number of pixels
// Parameter 2 = Trinket pin number 
// Parameter 3 = pixel type flags, add together as needed:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  strip.begin();
  strip.setPixelColor(0, 255, 0, 0); // pixel color set to red
  strip.setBrightness(255); // pixel set to full brightness
}


void loop() 
    {
      strip.setBrightness(random(150,255)); // random brightness adjust for flicker effect
      strip.show();
      delay(random(0,200)); // random delay for flicker effect
  }

OK. Thanks for the input Delta_G. Figured it out. And yes, I guess I could draw a couple boxes and lines. I was thinking more like an actual circuit drawing with the correct symbols and all. Anyway, I reworked my sketches slightly and ran the first 2 within setup and the 3rd in the loop. It works like a charm now. Here's what I did. Don't know if this is the best sketching, but it works just fine for my needs.

#include <Adafruit_NeoPixel.h>

#define PIN 1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  
  strip.begin();
  strip.setPixelColor(0, 255, 255, 0); // pixel color set to yellow
  strip.show();

  void engineBrighten();

  // begin brightening 0 to 255
    
  int i = 0;
   
  do {  
    i = i+1;
    strip.setBrightness(0+i); // brings up brightness from 0 to full
    strip.show();
    delay (40); // speed of brightness adjustment
    } while (i < 255);

   void engineColorFade();

   // begin color fade yellow to red
    
 int c = 255;
   
   do {
    c = c-1;
    strip.setPixelColor(0, 255, c, 0); // set pixel color
    strip.show();
    delay(25); // speed of color fade
   } while (c >0);
}
   
void loop() 
    {
      // begin engine flicker
      
      strip.setBrightness(random(150,255)); // random brightness adjust for flicker effect
      strip.show();
      delay(random(0,200)); // random delay for flicker effect
  }

Delta_G:
While that stuff is nice, and you certainly could use the internet and find all the symbols I'm sure, sometimes we just need to know how you wired the thing up.

Got it. Thanks. If I need help again on something (which I probably will), I'll be sure to do that up front.