Sub SendByte(ByVal DataByte As Byte)
dim i as byte
For I = 0 To 7 ' Loop 8 times for 8 bits
' send bits msb to lsb
If DataByte.bits(7) = 1 Then ' Send a '1' bit
' Send 1-bit (T1H: ~0.8us HIGH, T1L: ~0.45us LOW)
' T1H: 4 instruction cycles (0.8us)
' T1L: 2-3 instruction cycles (0.4-0.6us)
WS2812BDataPin = 1
NOP ' 200ns
NOP ' 400ns
NOP ' 600ns
NOP ' 800ns (approx T1H)
WS2812BDataPin = 0
NOP ' 200ns
NOP ' 400ns (approx T1L)
Else ' Send a '0' bit
' Send 0-bit (T0H: ~0.4us HIGH, T0L: ~0.85us LOW)
' T0H: 2 instruction cycles (0.4us)
' T0L: 4-5 instruction cycles (0.8-1.0us)
WS2812BDataPin = 1
NOP ' 200ns
NOP ' 400ns (approx T0H)
WS2812BDataPin = 0
NOP ' 200ns
NOP ' 400ns
NOP ' 600ns
NOP ' 800ns (approx T0L)
NOP ' 1000ns (Optional, for slightly longer T0L if needed)
End If
DataByte = DataByte << 1
Next
End Sub