First commit

This commit is contained in:
2024-02-27 12:42:35 +01:00
commit 9bbd50c4f5
23 changed files with 1324 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/*
* ATTENTION: This example uses the old v1.0 interface.
*
* Light_WS2812 library example - Chained Writes
*
* This example shows how to use multiple calls without issuing a reset
* in between, allowing to send the same buffer to the string
* multiple times. This technique can be useful to conserve memory
* or to calculate LED colors on-the-fly.
*
* Please make sure to set your configuration in "WS2812_config.h" first
*
*/
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "light_ws2812.h"
struct cRGB led[2];
int main(void)
{
uint8_t pos=0;
uint8_t direction=1;
uint8_t i;
#ifdef __AVR_ATtiny10__
CCP=0xD8; // configuration change protection, write signature
CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
#endif
led[0].r=16;led[0].g=00;led[0].b=00; // LED 0 is red
led[1].r=16;led[1].g=16;led[1].b=16; // LED 1 is White
while(1)
{
for (i=0; i<pos; i++)
ws2812_sendarray((uint8_t *)&led[0],3); // Repeatedly send "red" to the led string.
// No more than 1-2µs should pass between calls
// to avoid issuing a reset condition.
for (i=0; i<(16-pos); i++)
ws2812_sendarray((uint8_t *)&led[1],3); // white
_delay_ms(50); // Issue reset and wait for 50 ms.
pos+=direction;
if ((pos==16)||(pos==0)) direction=-direction;
}
}

View File

@@ -0,0 +1,45 @@
/*
* Light_WS2812 library example - RGBW_blinky
*
* cycles one LED through red, green, blue, white
*
* This example does only work with the SK6812RGBW LEDs
*
* Please make sure to set your configuration in "WS2812_config.h" first
*
*/
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "light_ws2812.h"
struct cRGBW led[1];
int main(void)
{
#ifdef __AVR_ATtiny10__
CCP=0xD8; // configuration change protection, write signature
CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
#endif
while(1)
{
led[0].r=128;led[0].g=00;led[0].b=0;led[0].w=0; // Write red to array
ws2812_setleds_rgbw(led,1);
_delay_ms(500); // wait for 500ms.
led[0].r=0;led[0].g=128;led[0].b=0;led[0].w=0; // green
ws2812_setleds_rgbw(led,1);
_delay_ms(500);
led[0].r=0;led[0].g=0;led[0].b=128;led[0].w=0; // blue
ws2812_setleds_rgbw(led,1);
_delay_ms(500);
led[0].r=0;led[0].g=0;led[0].b=0;led[0].w=128; // white
ws2812_setleds_rgbw(led,1);
_delay_ms(500);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Light_WS2812 library example - RGB_blinky
*
* cycles one LED through red, green, blue
*
* This example is configured for a ATtiny85 with PLL clock fuse set and
* the WS2812 string connected to PB4.
*/
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "light_ws2812.h"
struct cRGB led[1];
int main(void)
{
#ifdef __AVR_ATtiny10__
CCP=0xD8; // configuration change protection, write signature
CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
#endif
while(1)
{
led[0].r=255;led[0].g=00;led[0].b=0; // Write red to array
ws2812_setleds(led,1);
_delay_ms(500); // wait for 500ms.
led[0].r=0;led[0].g=255;led[0].b=0; // green
ws2812_setleds(led,1);
_delay_ms(500);
led[0].r=0;led[0].g=00;led[0].b=255; // blue
ws2812_setleds(led,1);
_delay_ms(500);
}
}

View File

@@ -0,0 +1,84 @@
/*
*
* This example is configured for a Atmega32 at 16MHz
*/
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "light_ws2812.h"
#define MAXPIX 30
#define COLORLENGTH (MAXPIX/2)
#define FADE (256/COLORLENGTH)
struct cRGB colors[8];
struct cRGB led[MAXPIX];
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++;
if(j>7)
{
j=0;
}
k=0;
}
k++;
//loop colouers
//fade red
if(led[0].r<(colors[j].r-FADE))
led[0].r+=FADE;
if(led[0].r>(colors[j].r+FADE))
led[0].r-=FADE;
if(led[0].g<(colors[j].g-FADE))
led[0].g+=FADE;
if(led[0].g>(colors[j].g+FADE))
led[0].g-=FADE;
if(led[0].b<(colors[j].b-FADE))
led[0].b+=FADE;
if(led[0].b>(colors[j].b+FADE))
led[0].b-=FADE;
_delay_ms(10);
ws2812_sendarray((uint8_t *)led,MAXPIX*3);
}
}