Instructables

Step 3: The algorithm works

Picture of The algorithm works
max.jpg
efect.jpg.jpg
all.jpeg.jpg
The algorithm itself is quite simple.

The task was as follows.
When crossing the infrared beam at the bottom of the stairs - the LEDs smoothly light on upwards.
When crossing the infrared beam at the top of the stairs - the LEDs light on down smoothly.
In case when both beams are crossed at the same time- all the LEDs light on smoothly

After a certain time, preset using the display and the keyboard the LEDs light down smoothly in the same direction, in which it has been turned on.

All the delays are set and controlled by the display.
Several iluminating effects can be find in the menu. 
And the choice of outputs (1 to 16)

The program was written in CodeVisionAVR.
I will not post the whole code , but here are some main points:

unsigned char mask;

void processUp(){
if(datUp==0) {
delay_ms(50);  
    for (mask = 0x01; mask; mask <<= 1)
    {
        PORTC |= mask;
        wait1();   /
    }

    // delay
    wait1();   // delay before lighting down

    //now lights off (in the same direction)
    for (mask = 0x01; mask; mask <<= 1)
//   for opposite direction:
    //for (mask = 0x80; mask; mask >>= 1)
    {
        PORTC &= ~mask;
        wait1();
    
    }
}
}