Combining sketches to make a music player with LEDs

I am very new to Arduino and appreciate any help I could get here. I have successfully completed projects to make an Arduino Light Instrument and the Fancy Sensing project from the Starter Kit Guidebook. What I'd like to do now is combine them so, using just one Arduino board, I could use the photo sensors to control the sound (as in the Light Instrument) and the soft pot to control the LED (as in the Fancy Sensing project). Is this possible? If so, how do I do this? The sketches are below. Thank you for any advice!

Light Instrument Sketch

/ LED leads connected to PWM pins

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

void setup() {

//no need for any code here


void loop() {

int sensorValue = analogRead(0); //read the Soft Pot

int redValue = constrain(map(sensorValue, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 over the range 0-512)

int greenValue = constrain(map(sensorValue, 0, 512, 0, 255),0,255)-constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the green value (0-255 over 0-512 & 255-0 over 512-1023)

int blueValue = constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over 512-1023

// Display the requested color

analogWrite(RED_LED_PIN, redValue);

analogWrite(GREEN_LED_PIN, greenValue);

analogWrite(BLUE_LED_PIN, blueValue);


Fancy Sensor Sketch

void setup() {
void loop() {
int sensorReading = analogRead(A0);
int sensorReading1 = analogRead(A1);
int thisPitch1 = map(sensorReading, 400, 1000, 120, 1500);
tone(10, thisPitch1, 10); // change the last value to change how long the speaker holds it's tone for.
delay(100); // Change delay time for different timing, but don't go under tone duration of 10.
int thisPitch2 = map(sensorReading1, 400, 1000, 120, 1500);
tone(11, thisPitch2, 10);

Please use code tags.

How to use this forum