How to combine these two codes

How do I combine these two codes so they work properly together without malfunction? I've gotten very close at a few attempts where they work combined but not in a proper way.

int greenLed = 7;
int yellowLed = 6;
int redLed = 5;

int analogValue = 0;
float voltage = 0;
int ledDelay = 1000;

#define Tone_G 392 // Define Tone G
#define Tone_A 440 // Define Tone A
#define Tone_B 494 // Define Tone B
const int buttonPin = 11;
const int Sound = 12; // For the speakers - sound will occur on Pin 11

const int ledPin4 = 4;
const int ledPin3 = 3;
const int ledPin2 = 2;
int buttonState = 0;        

void setup()
{
  pinMode(ledPin4, INPUT);
  pinMode(ledPin3, INPUT);
  pinMode(ledPin2, INPUT);
  
  pinMode(greenLed, INPUT);
  pinMode(yellowLed,INPUT);
  pinMode(redLed, INPUT);
  
  pinMode(buttonPin, INPUT);
  pinMode(Sound, INPUT); //speaker

  digitalWrite(ledPin4, HIGH); // Turn built-in LED on  
  tone(Sound, Tone_G, LOW); // Tone to play out of speaker. This Tone is G
  delay(200);
  digitalWrite(ledPin3, HIGH); // Turn built-in LED on
  tone(Sound, Tone_A, LOW); // Tone to play out of speaker. This Tone is A
  delay(200);
  digitalWrite(ledPin2, HIGH); // Turn built-in LED on
  tone(Sound, Tone_B, LOW); // Tone to play out of speaker. This Tone is B
  delay(200);
  noTone(Sound); // No Sound
  delay(1000);
  digitalWrite(ledPin2, LOW); // Turn built-in LED on
  delay(200);
  digitalWrite(ledPin3, LOW); // Turn built-in LED on
  delay(200);
  digitalWrite(ledPin4, LOW); // Turn built-in LED on
  delay(200);
  noTone(Sound); // No Sound
}

void loop(){
 
  delay(ledDelay);
  
  digitalWrite(redLed, LOW);
  delay(100);
  
  digitalWrite(yellowLed, LOW);
  delay(100);

  digitalWrite(greenLed, LOW);
  delay(100);

   // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LEDS on:
    digitalWrite(ledPin4, HIGH);
    delay(200);
    digitalWrite(ledPin3, HIGH);
    delay(200);
    digitalWrite(ledPin2, HIGH);
    delay(200);
    
    } 
  
  else {
    // turn LEDS off:
    digitalWrite(ledPin2, LOW);
    
    delay(100);
    digitalWrite(ledPin3, LOW);
    
    delay(100);
    digitalWrite(ledPin4, LOW);
   
    delay(100);
    
  }
  
}

SECOND CODE

int Pin13 = 13; 
// the setup routine runs once when you press reset:
void setup() {
  pinMode(Pin13, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
if (voltage <3.00){  
  digitalWrite(Pin13, LOW); 
  delay(1000);           
  digitalWrite(Pin13, HIGH);   
  delay(1000);             
}}

Define "work together" and "malfunction"

I've gotten very close at a few attempts

But you didn't post any of them

pinMode(greenLed, INPUT); Unusual..

@OP
greenLed is an output device which is being driven by DPin-7; so, the direction of DPin-7 should be INPUT or OUTPUT?

Never mind got it to work :slight_smile: