Monday, September 10, 2012

Comments


byte ledPin[] = {
  4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  //stores an 8-bit unsigned number for these inputs/outputs. Positions for the LEDS.
int ledDelay(65);
//int means interger. In this case, the delay is 65 seconds
int direction = 1;
//starting direction
int currentLED = 0;
//starting LED
unsigned long changeTime;
//an int that stores only positive 32 bits. Introducing variable.

void setup() {
  //starts the sketch
  for(int x=0; x<10; x++) {
 
    pinMode(ledPin[x], OUTPUT);
  }
//for numbers less than 10 pinMode increase by 1.
  changeTime = millis();
}
//time changes by milliseconds
void loop() {
//loops the sketvh
  if((millis() - changeTime) > ledDelay) {
    //if is a conditional statement. If time minus the time change is greater than the delay then the loop will start.
    changeLED();
    //this is a function that's defined below
    changeTime = millis();
  }
}
//if the millseconds minus the change in time is greater than 65 the LED switches

void changeLED() {
  for (int x = 0; x<10; x++) {
     //for is a statement is used to repeat a block of statements enclosed in curly brackets.
    digitalWrite(ledPin[x], LOW);
  }
//ChangeLED is defined by the void function. For all numbers less than 10 the LedPin increases by 1.

  digitalWrite(ledPin[currentLED], HIGH);
  //writes a high value in the the current LED
  currentLED += direction;
  //the currentLED with a high value equals direction
  if(currentLED == 9) {
    //once the led reaches the last position it goes back the other way.
    direction = -1;
  }
  //if you reach the 10th lED the direction changes
  if (currentLED == 0) {
     //once the led reaches the first position it goes back the other way.
    direction = 1;
  }
  //if you reached the first LED the position direction changes
}

//you can the direction the light go in. Which LEDs are used. You can change the speed and delay.

No comments:

Post a Comment