hi i got coe problem

hi everyone

i was wondering if u can help me

i want run two of the same codes at the same time.

i got 2 10kpots and both pots controlling one RBG led
i got the code for a single one two work but i dont know how to control both of on Code

RBG LED 1

const int RED_LED_PIN = 9; // Red LED Pin
const int GREEN_LED_PIN = 10; // Green LED Pin
const int BLUE_LED_PIN = 11; // Blue LED Pin
const int SENSOR_PIN = 0; // Analog input pin

RBG LED2
const int RED_LED_PIN = 3; // Red LED Pin
const int GREEN_LED_PIN = 5; // Green LED Pin
const int BLUE_LED_PIN = 6; // Blue LED Pin

const int SENSOR_PIN =1; // Analog input pin

Codes of one set of pot and led

const int RED_LED_PIN = 9; // Red LED Pin
const int GREEN_LED_PIN = 10; // Green LED Pin
const int BLUE_LED_PIN = 11; // Blue LED Pin
const int SENSOR_PIN = 0; // Analog input pin

int redValue, greenValue, blueValue;

void setup()
{

// No need for any code here
// analogWrite() sets up the pins as outputs
}

void loop()
{

int sensorValue;

// Read the voltage from the softpot (0-1023)

sensorValue = analogRead(0);

// We've written a new function called setRGB() (further down
// in the sketch) that decodes sensorValue into a position
// on the RGB "rainbow", and sets the RGB LED to that color.

setRGB(sensorValue);
}

// setRGB()
// Set a RGB LED to a position on the "rainbow" of all colors.
// RGBposition should be in the range of 0 to 1023 (such as
// from an analog input).

void setRGB(int RGBposition)
{
int mapRGB1, mapRGB2, constrained1, constrained2;

// Here we take RGBposition and turn it into three RGB values.

// The three values are computed so that the colors mix and
// produce a rainbow of colors across the 0-1023 input range.
// For each channel (red green blue), we're creating a "peak"
// a third of the way along the 0-1023 range. By overlapping
// these peaks with each other, the colors are mixed together.
// This is most easily shown with a diagram:
// Create the red peak, which is centered at 0.
// (Because it's centered at 0, half is after 0, and half
// is before 1023):

mapRGB1 = map(RGBposition, 0, 341, 255, 0);
constrained1 = constrain(mapRGB1, 0, 255);

mapRGB2 = map(RGBposition, 682, 1023, 0, 255);
constrained2 = constrain(mapRGB2, 0, 255);

redValue = constrained1 + constrained2;

/ / Create the green peak, which is centered at 341
// (one-third of the way to 1023):

// Note that we've nested the functions by putting the map()
// function inside the constrain() function. This can make your
// code more compact, and requires fewer variabls:

greenValue = constrain(map(RGBposition, 0, 341, 0, 255), 0, 255)

  • constrain(map(RGBposition, 341, 682, 0,255), 0, 255);

// Create the blue peak, which is centered at 682
// (two-thirds of the way to 1023):

blueValue = constrain(map(RGBposition, 341, 682, 0, 255), 0, 255)

  • constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255);

// Now we have all three brightnesses,
// we just need to display the computed color:

analogWrite(RED_LED_PIN, redValue);
analogWrite(GREEN_LED_PIN, greenValue);
analogWrite(BLUE_LED_PIN, blueValue);

Welcome to the Forum. Please read the two posts

How to use this forum - please read.
and
Read this before posting a programming question ...

at the top of this Forum on guidelines for posting here, especially the use of code tags which make the code look

like this

when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.

Also, you're missing a bracket at the end.

i got coe problem

Had to give up your Nike sponsorship too?

AWOL:
Had to give up your Nike sponsorship too?

You got there first -- nice one!

...R

i got the code for a single one two work but i dont know how to control both of on Code

What is the question, exactly? What happens? What do you expect to happen?

andrewvanlagen:
i want run two of the same codes at the same time.

i got 2 10kpots and both pots controlling one RBG led
i got the code for a single one two work but i dont know how to control both of on Code

Perhaps doing something like that:

struct led_t {byte potiPin; byte ledRedPin; byte ledGreenPin; byte ledBluePin;};

led_t leds[2]={
   { A0, 9, 10, 11},
   { A1, 3, 5, 6},
};

void setLedByIndex(int i)
{
  int sensorValue= analogRead(leds[i].potiPin);
  byte redValue, greenValue, blueValue;
  int mapRGB1, mapRGB2, constrained1, constrained2;

      // Here we take RGBposition and turn it into three RGB values.

      // The three values are computed so that the colors mix and 
      // produce a rainbow of colors across the 0-1023 input range.
      // For each channel (red green blue), we're creating a "peak"
      // a third of the way along the 0-1023 range. By overlapping
      // these peaks with each other, the colors are mixed together.
       // This is most easily shown with a diagram:
      // Create the red peak, which is centered at 0.
      // (Because it's centered at 0, half is after 0, and half
      // is before 1023):

  mapRGB1 = map(sensorValue, 0, 341, 255, 0);
  constrained1 = constrain(mapRGB1, 0, 255);

  mapRGB2 = map(sensorValue, 682, 1023, 0, 255);
  constrained2 = constrain(mapRGB2, 0, 255);

  redValue = constrained1 + constrained2;

          // Create the green peak, which is centered at 341
          // (one-third of the way to 1023):

    // Note that we've nested the functions by putting the map()
     // function inside the constrain() function. This can make your
     // code more compact, and requires fewer variabls:

  greenValue = constrain(map(sensorValue, 0, 341, 0, 255), 0, 255)
             - constrain(map(sensorValue, 341, 682, 0,255), 0, 255);

     // Create the blue peak, which is centered at 682
      // (two-thirds of the way to 1023):

  blueValue = constrain(map(sensorValue, 341, 682, 0, 255), 0, 255)
            - constrain(map(sensorValue, 682, 1023, 0, 255), 0, 255);

      // Now we have all three brightnesses,
       // we just need to display the computed color:

  analogWrite(leds[i].ledRedPin, redValue);
  analogWrite(leds[i].ledGreenPin, greenValue);
  analogWrite(leds[i].ledBluePin, blueValue);
}

void setup()
{
  // No need for any code here
  // analogWrite() sets up the pins as outputs
}

void loop()
{
  setLedByIndex(0);
  setLedByIndex(1);
}