#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>

#define WRAP 0

int main()
{
    uint8_t val = 0;
    int8_t  dir = 1;
    DDRD = 0xff;
    DDRB &= ~( 1 << PB0 );

    while(1)
    {
        if( !( PINB & ( 1 << PB0 ) ) ) {
            PORTD = 0x0 | ( 1 << val );
        } else {
            PORTD = 0xff & ~( 1 << val );
        }
#if WRAP
        val++;
        if( val > 7 ) val = 0;
#else
        val += dir;
        if( val == 7 || val == 0 ) dir = -dir;
#endif

        _delay_ms( 100 );
    }
}
