1

Тема: w2812

#define L_BIT    PORTB &= ~(1<<0)
#define H_BIT    PORTB |=  (1<<0)    

byte times;


void setup(){
   DDRB |= (1<<0);

   delayMicroseconds(1000); 

}

void loop(){ 
   if(times>254){times=0;}
   led(0x000000+times);
   led(0x000000);
   led(0x010000);
   led(0x000100);
   delayMicroseconds(100);
   times++;
   delay(10);
  }

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 led(unsigned long data){
  cli();
bit_w(data  & 0b100000000000000000000000);
bit_w(data  & 0b010000000000000000000000);
bit_w(data  & 0b001000000000000000000000);
bit_w(data  & 0b000100000000000000000000);
bit_w(data  & 0b000010000000000000000000);
bit_w(data  & 0b000001000000000000000000);
bit_w(data  & 0b000000100000000000000000);
bit_w(data  & 0b000000010000000000000000);

bit_w(data  & 0b000000000000000010000000);
bit_w(data  & 0b000000000000000001000000);
bit_w(data  & 0b000000000000000000100000);
bit_w(data  & 0b000000000000000000010000);
bit_w(data  & 0b000000000000000000001000);
bit_w(data  & 0b000000000000000000000100);
bit_w(data  & 0b000000000000000000000010);
bit_w(data  & 0b000000000000000000000001);  
    
bit_w(data  & 0b000000001000000000000000);    
bit_w(data  & 0b000000000100000000000000);    
bit_w(data  & 0b000000000010000000000000);    
bit_w(data  & 0b000000000001000000000000);    
bit_w(data  & 0b000000000000100000000000);    
bit_w(data  & 0b000000000000010000000000);    
bit_w(data  & 0b000000000000001000000000);    
bit_w(data  & 0b000000000000000100000000);    
   sei(); 
delayMicroseconds(20);
  }

2

Re: w2812

#define L_BIT    PORTB &= ~(1<<0)
#define H_BIT    PORTB |=  (1<<0)    

byte times;


void setup(){
   DDRB |= (1<<0);
   delayMicroseconds(1000); 

}

void loop(){ 
   if(times>254){times=0;}
   led(255,0,0);
   led(0,255,0);
   led(0,0,255);
   led(255-times,255-times,50);
   delayMicroseconds(100);
   times++;
   delay(10);
  }

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 led(byte rrr, byte ggg, byte bbb){
  unsigned long data = ((rrr << 8) & 0xFF0000) | ((ggg << 8) & 0xFF00) | bbb;
  cli();
bit_w(data  & 0b100000000000000000000000);
bit_w(data  & 0b010000000000000000000000);
bit_w(data  & 0b001000000000000000000000);
bit_w(data  & 0b000100000000000000000000);
bit_w(data  & 0b000010000000000000000000);
bit_w(data  & 0b000001000000000000000000);
bit_w(data  & 0b000000100000000000000000);
bit_w(data  & 0b000000010000000000000000);

bit_w(data  & 0b000000000000000010000000);
bit_w(data  & 0b000000000000000001000000);
bit_w(data  & 0b000000000000000000100000);
bit_w(data  & 0b000000000000000000010000);
bit_w(data  & 0b000000000000000000001000);
bit_w(data  & 0b000000000000000000000100);
bit_w(data  & 0b000000000000000000000010);
bit_w(data  & 0b000000000000000000000001);  
    
bit_w(data  & 0b000000001000000000000000);    
bit_w(data  & 0b000000000100000000000000);    
bit_w(data  & 0b000000000010000000000000);    
bit_w(data  & 0b000000000001000000000000);    
bit_w(data  & 0b000000000000100000000000);    
bit_w(data  & 0b000000000000010000000000);    
bit_w(data  & 0b000000000000001000000000);    
bit_w(data  & 0b000000000000000100000000);    
   sei(); 
delayMicroseconds(10);
  }

3

Re: w2812

#define L_BIT    PORTB &= ~(1<<0)
#define H_BIT    PORTB |=  (1<<0)    

byte times;
int i=0;

void setup(){
   DDRB |= (1<<0);
}

void loop(){ 
  

    led(10, 0, 0);
     led(0, 10, 0);
      led(0, 0, 10);
       led(10, 0, 0);
    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 led(long rrr, int ggg, byte bbb){
  unsigned long data = ((rrr << 16) & 0xFF0000) + ((ggg << 8) & 0xFF00) + bbb;
  cli();
bit_w(data  & 0b100000000000000000000000);
bit_w(data  & 0b010000000000000000000000);
bit_w(data  & 0b001000000000000000000000);
bit_w(data  & 0b000100000000000000000000);
bit_w(data  & 0b000010000000000000000000);
bit_w(data  & 0b000001000000000000000000);
bit_w(data  & 0b000000100000000000000000);
bit_w(data  & 0b000000010000000000000000);

bit_w(data  & 0b000000000000000010000000);
bit_w(data  & 0b000000000000000001000000);
bit_w(data  & 0b000000000000000000100000);
bit_w(data  & 0b000000000000000000010000);
bit_w(data  & 0b000000000000000000001000);
bit_w(data  & 0b000000000000000000000100);
bit_w(data  & 0b000000000000000000000010);
bit_w(data  & 0b000000000000000000000001);  
    
bit_w(data  & 0b000000001000000000000000);    
bit_w(data  & 0b000000000100000000000000);    
bit_w(data  & 0b000000000010000000000000);    
bit_w(data  & 0b000000000001000000000000);    
bit_w(data  & 0b000000000000100000000000);    
bit_w(data  & 0b000000000000010000000000);    
bit_w(data  & 0b000000000000001000000000);    
bit_w(data  & 0b000000000000000100000000);    
   sei(); 
delayMicroseconds(10);
  
  }

4

Re: w2812

#define L_BIT    PORTB &= ~(1<<0)
#define H_BIT    PORTB |=  (1<<0)    
#define LED_MAX  4

byte times;
int i=0;
unsigned long data;
unsigned long dat[LED_MAX];

void setup(){
   DDRB |= (1<<0);
}

void loop(){
   
res();
  for(int i1=0; i<LED_MAX; i++)
  for(int i=0; i<LED_MAX; i++) {
  
  if(i%2==1)data_led(i,50,0,0);
  else data_led(i,0,0,50);
  led();
  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;
  return dat[num];
  }

void led(){
  for(i=0;i<LED_MAX;i++){data=dat[i];
  cli();
bit_w(data  & 0b100000000000000000000000);
bit_w(data  & 0b010000000000000000000000);
bit_w(data  & 0b001000000000000000000000);
bit_w(data  & 0b000100000000000000000000);
bit_w(data  & 0b000010000000000000000000);
bit_w(data  & 0b000001000000000000000000);
bit_w(data  & 0b000000100000000000000000);
bit_w(data  & 0b000000010000000000000000);

bit_w(data  & 0b000000000000000010000000);
bit_w(data  & 0b000000000000000001000000);
bit_w(data  & 0b000000000000000000100000);
bit_w(data  & 0b000000000000000000010000);
bit_w(data  & 0b000000000000000000001000);
bit_w(data  & 0b000000000000000000000100);
bit_w(data  & 0b000000000000000000000010);
bit_w(data  & 0b000000000000000000000001);  
    
bit_w(data  & 0b000000001000000000000000);    
bit_w(data  & 0b000000000100000000000000);    
bit_w(data  & 0b000000000010000000000000);    
bit_w(data  & 0b000000000001000000000000);    
bit_w(data  & 0b000000000000100000000000);    
bit_w(data  & 0b000000000000010000000000);    
bit_w(data  & 0b000000000000001000000000);    
bit_w(data  & 0b000000000000000100000000);    
   sei(); 
delayMicroseconds(10);
  }
  }

5

Re: w2812

#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);
}}