user49622: I recently got into programing and I'm making an alarm. I cant figure out how to make a buzzer loop. I have two blinking LED's and two fading ones. Now I plan to have sound and it won't work.  It only blinks once and stops. I would also like the two fading LED's to fade at different times. I can't figure that out. Here's the code. 8 is the buzzer and red and blue are the fading LED's.
int blue = 6;
int red = 9;
int brightness = 0;
int fadeAmount = 500;

void setup() {
  pinMode(11,OUTPUT);
   pinMode(12,OUTPUT);
    pinMode(red, OUTPUT);
     pinMode(blue, OUTPUT);
      pinMode(8, OUTPUT);
}

void loop() {
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  delay(200);
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  delay(200);
  digitalWrite(8, LOW);
  digitalWrite(8, HIGH);
  delay(10);

 analogWrite(red, brightness);
  analogWrite(blue, brightness);
   brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) {
  fadeAmount = -fadeAmount;
}
 millis();
}


user49673: Have a look here, on how you can use different peripherals in a  non-blocking manner. The following code is from the link:
// These variables store the flash pattern
// and the current state of the LED

int ledPin1 =  12;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis1 = 0;        // will store last time LED was updated
long OnTime1 = 250;           // milliseconds of on-time
long OffTime1 = 750;          // milliseconds of off-time

int ledPin2 =  13;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 0;        // will store last time LED was updated
long OnTime2 = 330;           // milliseconds of on-time
byte brightness = 0;
byte brigthnessInterval = 10;

void setup() 
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);      
  pinMode(ledPin2, OUTPUT);      
}

void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();

  if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis1 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);     // Update the actual LED
  }

  if(currentMillis - previousMillis2 >= OnTime2)
  {
    previousMillis2 = currentMillis;  // Remember the time
    if (brigthness <= 254) brigthness += brigthnessInterval;
    if (brigthness == 255) brigthness = 0;
    analogWrite(ledPin2, brigthness);
  }
}

Here, two LEDs are controlled with different intervals, I changed LED number 2 to fade in with an interval specified with OnTime2; watch out your fade amount though, because analogWrite has 255 levels, and you immediately increased it to 500. You can add as many intervals as you want in the same manner, and perform tasks in pseudoparallel.

49622: <p>I recently got into programing and I'm making an alarm. I cant figure out how to make a buzzer loop. I have two blinking LED's and two fading ones. Now I plan to have sound and it won't work.  It only blinks once and stops. I would also like the two fading LED's to fade at different times. I can't figure that out. Here's the code. 8 is the buzzer and red and blue are the fading LED's.</p>

<pre><code>int blue = 6;
int red = 9;
int brightness = 0;
int fadeAmount = 500;

void setup() {
  pinMode(11,OUTPUT);
   pinMode(12,OUTPUT);
    pinMode(red, OUTPUT);
     pinMode(blue, OUTPUT);
      pinMode(8, OUTPUT);
}

void loop() {
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  delay(200);
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  delay(200);
  digitalWrite(8, LOW);
  digitalWrite(8, HIGH);
  delay(10);

 analogWrite(red, brightness);
  analogWrite(blue, brightness);
   brightness = brightness + fadeAmount;

if (brightness &lt;= 0 || brightness &gt;= 255) {
  fadeAmount = -fadeAmount;
}
 millis();
}
</code></pre>
 49673: <p>Have a look <a href="https://learn.adafruit.com/multi-tasking-the-arduino-part-1/now-for-two-at-once" rel="nofollow noreferrer">here</a>, on how you can use different peripherals in a  non-blocking manner. The following code is from the link:</p>

<pre><code>// These variables store the flash pattern
// and the current state of the LED

int ledPin1 =  12;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis1 = 0;        // will store last time LED was updated
long OnTime1 = 250;           // milliseconds of on-time
long OffTime1 = 750;          // milliseconds of off-time

int ledPin2 =  13;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 0;        // will store last time LED was updated
long OnTime2 = 330;           // milliseconds of on-time
byte brightness = 0;
byte brigthnessInterval = 10;

void setup() 
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);      
  pinMode(ledPin2, OUTPUT);      
}

void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();

  if((ledState1 == HIGH) &amp;&amp; (currentMillis - previousMillis1 &gt;= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis1 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) &amp;&amp; (currentMillis - previousMillis1 &gt;= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);     // Update the actual LED
  }

  if(currentMillis - previousMillis2 &gt;= OnTime2)
  {
    previousMillis2 = currentMillis;  // Remember the time
    if (brigthness &lt;= 254) brigthness += brigthnessInterval;
    if (brigthness == 255) brigthness = 0;
    analogWrite(ledPin2, brigthness);
  }
}
</code></pre>

<p>Here, two LEDs are controlled with different intervals, I changed LED number 2 to fade in with an interval specified with OnTime2; watch out your fade amount though, because analogWrite has 255 levels, and you immediately increased it to 500. You can add as many intervals as you want in the same manner, and perform tasks in pseudoparallel.</p>
