WS2812_SCAN - Exercise a WS2812 LED with different timing parameters. For each set of timing parameters (j,k) the following is performed: - Wait 10µs to reset the WS2812 LED - Emit 48 pulses with the given timing Compiles with AVR-GCC for ATtiny85. LED is connected on PB1.
/* | |
* WS2812_SCAN.c | |
* | |
* Created: 10.01.2014 20:46:20 | |
* Author: tim | |
*/ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
CLKPR=_BV(CLKPCE); // CLKDIV=1 | |
CLKPR=0; | |
DDRB|=_BV(PB1); // Enable 0C0B/PB1 | |
PORTB&=~_BV(PB1); // Set GPIO to low for the reset phase | |
TCCR0A=0; // PWM output off | |
TCCR0B=_BV(WGM02)|_BV(CS00); | |
while(1) { | |
uint8_t i; | |
int j,k; | |
_delay_ms(1); // delay before start of sequence | |
for(k=4; k<64; k++) { | |
for (j=0; j<k ;j++) { | |
_delay_us(10); // Reset | |
{ | |
OCR0A=k; // Total pulse length in clockcycles | |
OCR0B=j; // "On" time in clockcycles | |
TCNT0=0; | |
TCCR0A=_BV(COM0B1)|_BV(WGM01)|_BV(WGM00); | |
TIFR|=_BV(OCF0A); | |
for (i=0; i<48; i++) { // Emit 48 pulses | |
while (!(TIFR&_BV(OCF0A))); | |
TIFR|=_BV(OCF0A); | |
} | |
TCCR0A=0; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment