Skip to content

Instantly share code, notes, and snippets.

@MarkKropf
Created August 5, 2013 22:08
Show Gist options
  • Save MarkKropf/6160024 to your computer and use it in GitHub Desktop.
Save MarkKropf/6160024 to your computer and use it in GitHub Desktop.
Octobars / Shiftbrite ( Allegro A6281 ) SPI Packet Sender
def sb_SendPacket(r=0,g=0,b=0,c=0b00,packet=0)
packet = (packet << 2) | (c & 0b11)
packet = (packet << 10) | (b)
packet = (packet << 10) | (r)
packet = (packet << 10) | (g)
bits = packet.to_s(2).rjust(32, "0").chars.to_a
bits.insert(22, "_").insert(12, "_").insert(2, "_").insert(1, "_")
bit_str = bits.join("")
c_str = c.to_s(2).rjust(2,"0")
r_str = r.to_s(2).rjust(10,"0")
g_str = g.to_s(2).rjust(10,"0")
b_str = b.to_s(2).rjust(10,"0")
s1 = 0b11111111_00000000_00000000_00000000
s2 = 0b00000000_11111111_00000000_00000000
s3 = 0b00000000_00000000_11111111_00000000
s4 = 0b00000000_00000000_00000000_11111111
sval1 = ((s1 & packet) >> 24)
sval2 = ((s2 & packet) >> 16)
sval3 = ((s3 & packet) >> 8)
sval4 = ((s4 & packet))
@spi.write [sval1, sval2, sval3, sval4]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment