How do I combine codes so they work together?

How do I program them together please give me the programming codes. help me!!

Sketch number 1:
Reading a Potentiometer ( SIK Experiment Guide for Arduino - V3.2 - SparkFun Learn )

AND

Sketch number 2:
Driving an RGB LED- ( SIK Experiment Guide for Arduino - V3.2 - SparkFun Learn )

how do I combine them?

OR

Two experiment to do are
Reading a Potentiometer and Driving an RGB LED

"Combination Circuit Challenge 1: Reading a Potentiometer and Driving an RGB LED

Add the Potentiometer to the RGB LED and have the showSpectrum() function run from the value read off of the potentiometer" This is the assignment please help.

How do I program these two experiment so they both work please help.

Thanks

For school project, you should seek the instructor's help. They are paid to do exactly that.

For hobby project, you should at least try. Google how to combine arduino sketches.

For work project, you should pay someone else to try.

Hi, Some help on ArduinoInfo.Info here:

https://arduinoinfo.mywikis.net/wiki/WritingAndUnderstandingSketches

terryking228:
Hi, Some help on ArduinoInfo.Info here:

WritingAndUnderstandingSketches - ArduinoInfo

Hi can you please send me the codes please i need this please

Can you give us your teacher's email address so we can contact them and ask what our final grade is once the assignment is submitted?

If this is not homework, then you need to convince us that it isn't.

A first step would be to have a little insight how the standard Arduino codes work (setup and loop).

A second step would be to understand in depth the codes.

Next you take one of the sketches and you add the relevant statements of the other sketch in the other one.

Sketch 1 with many of the comments removed:

/* SparkFun Inventor's Kit, Example sketch 02 POTENTIOMETER */
int sensorPin = 0;    // The potentiometer is connected to analog pin 0
int ledPin = 13;      // The LED is connected to digital pin 13


void setup() // this function runs once when the sketch starts up
{
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  int sensorValue = analogRead(sensorPin);    

  digitalWrite(ledPin, HIGH);     // Turn the LED on
  delay(sensorValue);             // Pause for sensorValue milliseconds
  digitalWrite(ledPin, LOW);      // Turn the LED off
  delay(sensorValue);             // Pause for sensorValue milliseconds
}

Since you don't need to blink an LED, you can make it even simpler:

/* SparkFun Inventor's Kit, Example sketch 02 POTENTIOMETER */
int sensorPin = 0;    // The potentiometer is connected to analog pin 0

void setup() // this function runs once when the sketch starts up
{
}

void loop()
{
  int sensorValue = analogRead(sensorPin);    
}

That should be simple enough to understand. The active part is one line.

Sketch 2:

/* SparkFun Inventor's Kit, Example sketch 03, RGB LED */

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

int DISPLAY_TIME = 10;  // In milliseconds

void setup()
{
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
showSpectrum();
}

void showSpectrum()
{
  int x;  // define an integer variable called "x"

  for (x = 0; x < 768; x++)
  {
    showRGB(x);  // Call RGBspectrum() with our new x
    delay(DISPLAY_TIME);   // Delay for 10 ms (1/100th of a second)
  }
}

// This function translates a number between 0 and 767 into a
// specific color on the RGB LED. 

void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;

if (color <= 255)          // zone 1
{
redIntensity = 255 - color;    // red goes from on to off
greenIntensity = color;        // green goes from off to on
blueIntensity = 0;             // blue is always off
}
else if (color <= 511)     // zone 2
{
redIntensity = 0;                     // red is always off
greenIntensity = 255 - (color - 256); // green on to off
blueIntensity = (color - 256);        // blue off to on
}
else // color >= 512       // zone 3
{
redIntensity = (color - 512);         // red off to on
greenIntensity = 0;                   // green is always off
blueIntensity = 255 - (color - 512);  // blue on to off
}

// Now that the brightness values have been set, command the LED
// to those values

analogWrite(RED_PIN, redIntensity);
analogWrite(BLUE_PIN, blueIntensity);
analogWrite(GREEN_PIN, greenIntensity);
}

That sketch is also fairly simple. You just need to pass a number to showRGB(). That is one line of code. It takes a number from 0 to 767. Hint: the analogRead() returns a value from 0 to 1023.

Go look around the Introductory Tutorials section.
It has a thread that discusses merging two sketches.