/* * 20200125_tiny85_neopixel.c * * Created: 2020-01-25 17:13:13 * Author : uwezi */ // set LFUSE 0xC1 HFUSE 0xDF #define F_CPU 16000000UL #include #include #include #include #define T0H 0.1 #define T0L 0.9 #define T1H 0.7 #define T1L 0.4 #define WSPORT PORTB #define WSDDR DDRB #define WSPIN PB3 void send_byte(uint8_t outbyte) { uint8_t old_port, port_h, port_l; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { old_port = WSPORT; port_h = old_port | (1 << WSPIN); port_l = old_port & ~(1 << WSPIN); uint8_t i; for (i=0; i<8; i++) { if (outbyte & 0b10000000) { WSPORT = port_h; // here we set the pin to 1 _delay_us(T1H); WSPORT = port_l; _delay_us(T1L); } else { WSPORT = port_h; _delay_us(T0H); WSPORT = port_l; _delay_us(T0L); } outbyte = outbyte << 1; } WSPORT = old_port; } } int main(void) { if (F_CPU == 16000000UL) clock_prescale_set(clock_div_1); uint8_t i, j; WSDDR |= (1 << WSPIN); i = 0; while (1) { for (j=0; j<3*3; j++) { send_byte(i); } i++; _delay_ms(10); } }