Beispiel #1
0
//# MENU ws2812b
void ws1812b_menu(){
    uint8_t pattern[] = {
                     255, 255, 0,
                     255, 255, 0,

                     0,   0,   255,
                     0,   0,   255,
                     0,   0,   255,
                     0,   0,   255,
                     0,   0,   255,
                     255, 0,   0
                     };

    uint8_t green[] = {255, 0, 0};
	getInputWaitRelease();
    //cpu_clock_set(17);
    cpu_clock_set(51);
	SETUPgout(RGB_LED);

	while(1){
		lcdClear(0xff);
		lcdPrintln("WS2812B test");
		lcdPrintln("UP: pattern");
		lcdPrintln("DOWN: green");
		lcdPrintln("ENTER: exit");
		lcdDisplay();

		switch(getInput()){
			case BTN_UP:
                ws2812_sendarray(pattern, sizeof(pattern));
				break;
			case BTN_DOWN:
                ws2812_sendarray(green, sizeof(green));
				break;
			case BTN_LEFT:
				break;
			case BTN_RIGHT:
				break;
			case BTN_ENTER:
				return;
				break;
		};
	};
	return;
};
Beispiel #2
0
void writeToLeds()
{
	uint8_t i;

	cli();
	for (i=0; i<ledCount; i++) {
		ws2812_sendarray((uint8_t *)&led[i],3);
	}
	sei();
	
	_delay_us(50);
}
int main(void)
{
	uint8_t mask;
	
	#ifdef __AVR_ATtiny10__
		CCP=0xD8;		// configuration change protection, write signature
		CLKPSR=1;		// set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
		mask=_BV(PB2);
	#else
		CLKPR=_BV(CLKPCE);
		CLKPR=0;			// set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A)		
		mask=_BV(PB4);
	#endif
		DDRB|=mask;
	
	while(1)
    {
		cli();										// Disable interrupts. Can be ommited if no interrupts are used.
		led[0].r=255;led[0].g=00;led[0].b=0;		// Write red to array
		ws2812_sendarray((uint8_t *)&led[0],3);		// Send array to WS2812 LED. The output pin is low after send.
		sei();										// Enable interrupts.
		_delay_ms(500);								// Issue reset and wait for 500ms.
		
		cli();
		led[0].r=0;led[0].g=255;led[0].b=0;			// green
		ws2812_sendarray((uint8_t *)&led[0],3);
		sei();
		_delay_ms(500);

		cli();
		led[0].r=0;led[0].g=00;led[0].b=255;		// blue
		ws2812_sendarray((uint8_t *)&led[0],3);
		sei();
		_delay_ms(500);	
    }
}
Beispiel #4
0
void tick_rgbLeds(void) {
	if(GLOBAL(rgbleds)) {
		if(frames > 0) {
			if(ctr == 0) {
				ws2812_sendarray(&leds[framectr*3*8+2], 3*8);
				framectr++;
				if(framectr >= frames)
					framectr = 0;
			}

			ctr++;
			// LED delay is in leds[0:1]
			if(ctr >= ((leds[0]<<8) + leds[1]))
				ctr = 0;
		}
	}
	return;
}
Beispiel #5
0
void setLeds(){
	// Send update to all LEDs
	cli();				// Disable interrupts. Can be removed if no interrupts are used.
	ws2812_sendarray((uint8_t *)&led[0],42);
	sei();				// Enable interrupts.
}
Beispiel #6
0
int main(void)
{
	
	uint8_t j = 1;
	uint8_t k = 1;

	DDRB|=_BV(ws2812_pin);
		
    uint8_t i;
    for(i=MAXPIX; i>0; i--)
    {    
        led[i-1].r=0;led[i-1].g=0;led[i-1].b=0;
    }
		
    //Rainbowcolors
    colors[0].r=150; colors[0].g=150; colors[0].b=150;
    colors[1].r=255; colors[1].g=000; colors[1].b=000;//red
    colors[2].r=255; colors[2].g=100; colors[2].b=000;//orange
    colors[3].r=100; colors[3].g=255; colors[3].b=000;//yellow
    colors[4].r=000; colors[4].g=255; colors[4].b=000;//green
    colors[5].r=000; colors[5].g=100; colors[5].b=255;//light blue (türkis)
    colors[6].r=000; colors[6].g=000; colors[6].b=255;//blue
    colors[7].r=100; colors[7].g=000; colors[7].b=255;//violet
    
	while(1)
    {
        //shift all vallues by one led
        uint8_t i=0;           
        for(i=MAXPIX; i>1; i--) 
            led[i-1]=led[i-2];
        //change colour when colourlength is reached   
        if(k>COLORLENGTH)
        {
            j++;
            k=0;
        }
        k++;
        //loop colouers
        if(j>8)
            j=0;
        
        //fade red
        if(led[0].r<colors[j].r)
            led[0].r+=FADE;
        if(led[0].r>255.r)
            led[0].r=255;
            
        if(led[0].r>colors[j].r)
            led[0].r-=FADE;
    //    if(led[0].r<0)
    //        led[0].r=0;
        //fade green
        if(led[0].g<colors[j].g)
            led[0].g+=FADE;
        if(led[0].g>255)
            led[0].g=255;
            
        if(led[0].g>colors[j].g)
            led[0].g-=FADE;
    //    if(led[0].g<0)
    //        led[0].g=0;
        //fade blue
        if(led[0].b<colors[j].b)
            led[0].b+=FADE;
        if(led[0].b>255)
            led[0].b=255;
            
        if(led[0].b>colors[j].b)
            led[0].b-=FADE;
    //    if(led[0].b<0)
    //        led[0].b=0;

		 _delay_ms(10);										
		 ws2812_sendarray((uint8_t *)led,MAXPIX*3);
    }
}