combining two sketches

I have two sketches that are working almost ok on there own but I need to combine them.
When I try to they seem to cancel each other out,
Would someone be willing to take a look and see why they don't seem to be compatible?

Thanks

Cory

http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Hey clown, how can we do that if you don't post the code or describe what the program is supposed to do or what it actually does?

PaulS

Thanks! I guess I felt I should ask first.

Both of these sketches use a potentiometer so when they're combined I would need two potentiometers one for each movement.

One sketch EYE_1 works great. I can adjust the amount of pixels that are in the cluster, their color. they can move back and forth over another color that can also have it's width set, larger or smaller so the cluster can move over the second color.

The other sketch Mouth_1 is almost working correctly. They're supposed to be a designated amount of a blanket of a color. When the potentiometer is moved the pixels should expand from the center point and then contract to the same point leaving the blanket of color. The way this one works is wrong because it writes the blanket of color as it is expanding and then the blanket remains as it expands and contracts. I need to be able to pick a pixel that I would want this expansion to begin from.

This all has to be on one strip of neo-pixels. I tried combining the two sketches and it seems that they cancel each other out. I have been trying for days.

Any help would be greatly appreciated.

Thank you so much you're time,

Cory

#include <Adafruit_NeoPixel.h>

//EYE_!

#define PIN 5
#define NUM_PIXELS 31

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);

const byte potPin = A0;
const byte potPin2 = A2;
int litPixel = (6);
int Brightness = 0;



void setup()
{
  pixels.begin(); // This initializes the NeoPixel library
 
}

void loop()
{
  int newPixel = map(analogRead(potPin2), 0, 1023, 20, 25);
  pixels.setBrightness(10);
  if (newPixel != litPixel)
  {
    for (int i = 21; i < NUM_PIXELS; i++)
    for (int j = 0; j <21; j++)
    {
      if (i > newPixel && i < newPixel+6)
      {
          pixels.setPixelColor(i, pixels.Color(0,0, 255));
          pixels.setPixelColor(j, pixels.Color(100,0, 100));
          
      }
      else
      {
           pixels.setPixelColor(i, pixels.Color(255, 255, 255));
      }
    }
    pixels.show(); // This sends the updated pixel color to the hardware.
    litPixel = newPixel;
  }
}
// 
//Arduino code for Neopixel LED controller
// using a potentiometer and switch button
// (C) Ismail Uddin, 2015
// www.scienceexposure.com

//Mouth_1

#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR // Make Arduino Due happy
#endif

#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 31
#define DATA_PIN 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(31, DATA_PIN, NEO_GRB + NEO_KHZ800);

int potPin = A0;
int potPin2 = A2;
int val = 0;
int val_2 = 0;
int colorVal = 0;
int reading = 0;
int x;
int i;
int prevVal = 0;
int prevVal_2 = 0;
int switchPin = 13;
boolean lastBtn = LOW;
boolean NeopixelColor = false;
boolean lastButton = LOW;

uint32_t c_orange = strip.Color(248, 73, 3);

CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  strip.begin();
  strip.show();
  FastLED.show();
  //pinMode(switchPin, INPUT);
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   }

void loop() {
  // put your main code here, to run repeatedly:
  //leds[25] = CRGB::Red; 
        //FastLED.show(); 
        //delay(30); 
    //strip.setPixelColor(0-31,100,0,100);
    //strip.setPixelColor(20,100,0,100);
  reading = analogRead(potPin);
  //reading = analogRead(potPin_2);
  val = (reading/1024.0) * 10;
  //val_2 = (reading/1024.0) * 25;
  colorVal = (reading/1024.0) * 255;
  
  //if (digitalRead(switchPin) == HIGH && lastButton == LOW)
  {
    //delay(250); // Account for contact debounce
    //NeopixelColor = !NeopixelColor;
    
  }
  
  if (NeopixelColor == false)
  {
    // Neopixel LED number code
    strip.setBrightness(10);
    if (val != prevVal)
    //if (val_2 != prevVal_2)
    
    {
      for ( x = 0; x < val; x++)
      
      
      //for ( x = 0; x < val_2; x++) 
      
        //for ( x = 10; x >= val; x--);
      {
        strip.setPixelColor(10 + x,CRGB::Blue); // increasing *
        strip.setPixelColor(9 + x,CRGB::Blue); // increasing *
        strip.setPixelColor(10 - x,CRGB::Blue); // decreasing 
        //strip.setPixelColor(9 + x,0); // increasing *
        //strip.setPixelColor(11 - x,0); // decreasing
      }
      //for (x=val; x<22; x++)
      //for (x=val_2; x<31; x++) 
      { 
        strip.setPixelColor(10 + x,100,0,100); // increasing Erasing *
        strip.setPixelColor(10 - x,100,0,100); // decreasing Erasing
        //strip.setPixelColor(10 + x,0,0,0); // increasing
        //strip.setPixelColor(9 - x,0,0,0); // decreasing
        //strip.show();
      }
      prevVal = val;
      //prevVal_2 = val_2;
    }
//    else
    {
      strip.show();
    }
    
  }
  else
  {
    // Neopixel Color code
    for (x=0; x < prevVal; x++)
    {
    
    }
  }
}

PaulS

Bulldog did this sketch for me. He didn't test it, but it moves one pixel around and I think it looks like it should be able to grow in both directions from one pixel.

It loads but the growing in both directions is not working.
I tried many things with no luck. If you could take a look at it maybe it's an easy fix for you.

Thanks

Cory

#include <Adafruit_NeoPixel.h>

#define PIN 5
#define NUM_PIXELS 31

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);

const byte potPin = A0;
const byte potPin2 = A2;
int litPixel = (6);

int lastCenter = -1;
int lastStretch = -1;

void setup()
{
  pixels.begin();
  pixels.setBrightness(10);
}

void loop()
{
  int centerPixel = map(analogRead(potPin), 0, 1023, 0, NUM_PIXELS);
  int stretch = map(analogRead(potPin2), 0, 1023, 0, NUM_PIXELS / 2);
  if(centerPixel != lastCenter || stretch != lastStretch)
  {
    ledStripUpdate(centerPixel, stretch);
    lastStretch = stretch;
    lastCenter = centerPixel;
  }
}

void ledStripUpdate(int center, int ditherWidth)
{
  static int lastCenter = -1;
  for (int i = 0; i < NUM_PIXELS; i++)
  {
    if (i < center - ditherWidth)
    {
      pixels.setPixelColor(i, pixels.Color(100, 0, 100));
    }
    else if (i < center)
    {
      byte fadenum = constrain(map(i, center - ditherWidth, center, 0, 255), 0, 255);
      pixels.setPixelColor(i, pixels.Color(fadenum, fadenum, fadenum));
    }
    else if (i == center)
    {
      pixels.setPixelColor(i, pixels.Color(255, 255, 255));
    }
    else if (i < center + ditherWidth)
    {
      byte fadenum = constrain(map(i, center, center + ditherWidth, 255, 0), 0, 255);
      pixels.setPixelColor(i, pixels.Color(fadenum, fadenum, fadenum));
    }
    else
    {
      pixels.setPixelColor(i, pixels.Color(100, 0, 100));
    }
    pixels.setPixelColor(i, (i == center) ? pixels.Color(255, 255, 255) : pixels.Color(100, 0, 100));
  }
  pixels.show();
}