void Ws2822s::setAddress(int start_pixel, int end_pixel) { if (start_pixel < 0 || end_pixel >= 1024) return; if (start_pixel > end_pixel) return; *out_adri |= bit_address; delayMicroseconds(10); *out_adri &= ~bit_address; delayMicroseconds(5000); uint8_t oldSREG = SREG; cli(); *out_adri |= bit_address; delayMicroseconds(12); sendByte(0, out_adri, bit_address); *out_adri |= bit_address; for (int i = start_pixel; i <= end_pixel; ++i) { channel = i * 3 + 1; channel_rv = channel; channel_rv = ((channel_rv & 0x55) << 1) | ((channel_rv & 0xAA) >>1); channel_rv = ((channel_rv & 0x33) << 2) | ((channel_rv & 0xCC) >>2); channel_rv = ((channel_rv << 4) | (channel_rv >> 4)); sendByte((channel_rv & 0x00FF), out_adri, bit_address); if (channel >= 0 && channel < 256) temp = 0x0F; else if (channel >= 256 && channel < 512) temp = 0x87; else if (channel >= 512 && channel < 768) temp = 0x4B; else if (channel >= 768 && channel < 1024) temp = 0xC3; else if (channel >= 1024 && channel < 1280) temp = 0x2D; else if (channel >= 1280 && channel < 1536) temp = 0xA5; else if (channel >= 1536 && channel < 1792) temp = 0x69; else if (channel >= 1792 && channel < 2048) temp = 0xE1; else if (channel >= 2048 && channel < 2304) temp = 0x1E; else if (channel >= 2304 && channel < 2560) temp = 0x96; else if (channel >= 2560 && channel < 2816) temp = 0x5A; else if (channel >= 2816 && channel < 3072) temp = 0xD2; sendByte(temp, out_adri, bit_address); temp = 0x4B; sendByte(temp, out_adri, bit_address); } SREG = oldSREG; sei(); }