The operator <<
is a left-shift. It shifts each bit a number of positions to the left, and fills the missing pieces with zero:
1<<0 equals 0b00000001
1<<1 equals 0b00000010
1<<2 equals 0b00000100
... etc ...
If i
increments from 0 to 7 in a loop, you will get a pattern with a bit that appears to move through every position. The actual order of the LEDs will depend on your physical circuit. If you want it to move in a different direction, make i
go from 7 to 0 instead.
The delay is simply required to let you see anything at all. Without the delay, it would scroll through every position too fast to see anything at all. A delay in between makes it turn on the LED, wait a little so that you have time to react, and then turn it off again and leave it off for a while.
The last delay is optional. If you remove it, the effect will be slightly different.