Arduino C Program LED Blink

I wrote a little example Arduino C Program that lets the LEDs blink in 5 different ways. You could download the Software from Arduino – Software.

// the setup routine runs once when you press reset:
#define START_PIN 0
#define END_PIN 7

void setup() {                
  // initialize the digital pin as an output.
  for(int i = 0;i<=END_PIN;i++){
  pinMode(i, OUTPUT); 
  }  
}
int sleep = 40;
// the loop routine runs over and over again forever:
void loop() { 
  //mod 1
  for(int i = START_PIN;i<=END_PIN;i++){
  digitalWrite(i, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(sleep);               // wait for a second
  digitalWrite(i, LOW);    // turn the LED off by making the voltage LOW
  delay(sleep);               // wait for a second
  }
  for( int i = END_PIN;i>START_PIN;i--){
  digitalWrite(i, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(sleep);               // wait for a second
  digitalWrite(i, LOW);    // turn the LED off by making the voltage LOW
  delay(sleep);               // wait for a second
  }
  //mod 2
  for( int i = START_PIN;i<=END_PIN;i++){
    digitalWrite(i, HIGH);
  delay(sleep);  
  }
  for( int i = START_PIN;i<=END_PIN;i++){
  digitalWrite(i, LOW);
  }
  for( int i = END_PIN;i>START_PIN;i--){
  digitalWrite(i, HIGH); 
  delay(sleep); 
  }
  for( int i = START_PIN;i<=END_PIN;i++){
  digitalWrite(i, LOW);
  }
  //mod 3
  for(int x = 1;x<=START_PIN+END_PIN;x++){
    for( int i = START_PIN;i<=END_PIN;i++){
    digitalWrite(i, HIGH);
    }
    delay((sleep*10)/x);
    for( int i = START_PIN;i<=END_PIN;i++){
    digitalWrite(i, LOW);
    }
    delay((sleep*10)/x);
  }
  //mod 4
  for(int x = 0;x<=20;x++){
    for( int i = START_PIN;i<=END_PIN;i++){
      if(i%2){
        digitalWrite(i, HIGH);
      }else{
        digitalWrite(i, LOW);
      }
    }
    delay(sleep);
      for( int i = START_PIN;i<=END_PIN;i++){
      if(i%2){
        digitalWrite(i, LOW);
      }else{
        digitalWrite(i, HIGH);
      }
    }
    delay(sleep);
  }
  for( int i = START_PIN;i<=END_PIN;i++){
        digitalWrite(i, LOW);
    }
  //mod 5
  for(int i = 0,a=START_PIN+1,b=END_PIN;i<=20;i++,a++,b--){
    if(a >= END_PIN)a=START_PIN+1;
    if(b <= 6)b=END_PIN+START_PIN;
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  delay(sleep);
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  delay(sleep);
  }
}

 

3 thoughts on “Arduino C Program LED Blink”

  1. Now I am going to do my breakfast, afterward having my breakfast coming again to read more news.

  2. Having read this I thought it was really enlightening.
    I appreciate you spending some time and
    energy to put this article together. I once again find myself personally spending
    a significant amount of time both reading and posting comments.
    But so what, it was still worthwhile!

  3. Ahaa, its good dialogue about this article at this particular place at the
    weblog, We have read all of that, so currently me also commenting at
    the place.

Leave a Reply

Your email address will not be published.

5 − 4 =