//Example Code
int delayTime1 = 3333;
int delayTime2 = 333; //It's better coding style to not have any hard-coded constants like in the previous example
//byte portD_HIGH = B11111000;
//byte portD_LOW = B00000000;
byte portD_HIGH = B10101010;
byte portD_LOW = B01010101;
byte portB_HIGH = B101010;
byte portB_LOW = B010101;
void setup()
{
DDRD = DDRD | B11111111; //Sets up the pins for output
DDRB = DDRB | B111111; //Sets up the pins for output
//a look at what we just did
//the | symbol is used as bitwise OR (if either bit is 1, result will be 1)
//this goes through the register, ORing each bit with the binary to the right of the |
//the B makes the compiler read the 11111100 as binary
//So in summary it sets pins 2-7 to Output and leaves 1 and 2 (which sometimes
//have special functions) alone
}
void loop()
{
PORTD = portD_HIGH; //sets pin ledPin High (so pin 13 is set to 1)
delay(delayTime1); //waits 333ms or ~1/3 sec
PORTD = portD_LOW; //sets pin ledPin to Low (so pin 13 is now equal to 0)
delay(delayTime2); //waits another 333 ms
PORTB = portB_HIGH; //sets pin ledPin High (so pin 13 is set to 1)
delay(delayTime1); //waits 333ms or ~1/3 sec
PORTB = portB_LOW; //sets pin ledPin to Low (so pin 13 is now equal to 0)
delay(delayTime2); //waits another 333 ms
} //end of the loop subroutine, so it will now go back to the beginning
//All 5 LEDs should now be blinking merrily away.