#define L_BIT PORTB &= ~(1<<0)
#define H_BIT PORTB |= (1<<0)
#define LED_MAX 4
unsigned long data, dat[LED_MAX];
void setup(){
DDRB |= (1<<0);
}
void loop(){
for(int i1=0;i1<LED_MAX;i1++){
for(int i=0;i<50;i++){
data_led(i1, 50,50-i1*3,50-i);
led_rgb();res();
delay(10);
}}
for(int i1=0;i1<LED_MAX;i1++){
data_led(i1,0,0,0);
led_rgb();res();
delay(500);
}
}
void bit_0(){H_BIT;asm("nop");asm("nop"); L_BIT;asm("nop");asm("nop");asm("nop"); asm("nop");}
void bit_1(){H_BIT;asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop"); L_BIT;}
void bit_w(bool x){if(x) bit_1(); else bit_0();}
void res(){delayMicroseconds(100);}
void data_led(int num, long rrr, int ggg, byte bbb){
data = ((rrr << 16) & 0xFF0000) + ((ggg << 8) & 0xFF00) + bbb;
dat[num] = data;
}
void led_rgb(){
for(int num_i=0;num_i<LED_MAX;num_i++){data=dat[num_i];
cli();
bit_w(data & 0x80);
bit_w(data & 0x40);
bit_w(data & 0x20);
bit_w(data & 0x10);
bit_w(data & 0x08);
bit_w(data & 0x04);
bit_w(data & 0x02);
bit_w(data & 0x01);
bit_w(data & 0x800000);
bit_w(data & 0x400000);
bit_w(data & 0x200000);
bit_w(data & 0x100000);
bit_w(data & 0x080000);
bit_w(data & 0x040000);
bit_w(data & 0x020000);
bit_w(data & 0x010000);
bit_w(data & 0x8000);
bit_w(data & 0x4000);
bit_w(data & 0x2000);
bit_w(data & 0x1000);
bit_w(data & 0x0800);
bit_w(data & 0x0400);
bit_w(data & 0x0200);
bit_w(data & 0x0100);
sei();
delayMicroseconds(10);
}}