Copyright

Creative Commons License

This work is licenced under a Creative Commons Licence.

User login

Got attacked by Cylons

Bought an arduino uno. Got attacked by Cylons.

Code below nearly entirely robbed from ardx.org.

int ledPins[] = {2,3,4,5,6,7,8,9}; 
                                   
void setup()
{
  
  for(int i = 0; i < 8; i++){      
      pinMode(ledPins[i],OUTPUT); 
  }                               
 
}
 
void loop()        
{
  oneOnAtATime();  
}
 
 
void oneOnAtATime(){
  int delayTime = 100; 
                       
  //forwards
  for(int i = 0; i <= 7; i++){
    int offLED = i - 1; 
    if(i == 0) {    
      offLED = 7;   
    } 

    digitalWrite(ledPins[i], HIGH);     
    digitalWrite(ledPins[offLED], LOW); 
    delay(delayTime);
  }    
  //backwards    
  for(int i = 7; i >= 0; i--){
    int offLED = i + 1; 
    if(i == 7) {       
      offLED = 7;     
    }                 

    digitalWrite(ledPins[i], HIGH);     
    digitalWrite(ledPins[offLED], LOW); 
    delay(delayTime);
    
    }
 }