There is probably a simple solution...

I can't figure out how to connect the LED fade circuit and the circuit to read a button. I need to be able to read the button so the fade effect can be turned on or off and adjusted. I have the code, I just can't make the circuit. Please help.

Edit: here is the code I'm working with.
const int LED = 9;
const int BUTTON = 7;

int val = 0;

int old_val = 0;
int state = 0;

int brightness = 128;
unsigned long startTime = 0;

void setup(){
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}

void loop(){

val=digitalRead(BUTTON);

if ((val == HIGH) &&(old_val==LOW)){

state= 1-state;

startTime = millis();

delay(10);
}

if ((val==HIGH) && (old_val == HIGH)) {

if (state == 1 && (millis() - startTime) > 500) {

brightness++;
delay(10);

if (brightness

  1. {
    brightness =0;

}
}
}
old_val = val;

if (state ==1) {
analogWrite(LED, brightness);
}else{
analogWrite(LED, 0);
}
}

This is from Getting Started with Arduino by Massimo Banzi, if that helps.

Levitationist7:
I have the code

Feel free to post it so that we have more context in what you are trying to do.

When you say 'circuit' do you mean the hardware wiring circuit?

The two devices are wired to the Arduino independently - if you can wire them up individually, what's stopping you from wiring them both up at the same time?

Levitationist7:
I just can't make the circuit.

What problem are you having wiring the circuit? Hook up an LED like you would in any of the LED example and a button like you would in any of the button examples.