Permalink
Browse files

Slightly faster...

  • Loading branch information...
1 parent d478375 commit 67a6e731346ce8279d64602272fa9c6982666d02 @cibomahto cibomahto committed May 18, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 host/LedStrips.py
View
8 host/LedStrips.py
@@ -1,6 +1,7 @@
import serial
import time
import optparse
+import array
class LedStrips:
@@ -32,29 +33,30 @@ def RgbRowToStrips(self, data):
output = ''
+ data = array.array('B', data)
# Green byte
output += '\xFF'
for bit_index in range(7, 0, -1):
c = 0x00
for pixel_index in range(0, 8):
- c |= (ord(data[1+3*pixel_index]) >> bit_index & 1) << pixel_index
+ c += (data[1+3*pixel_index] >> bit_index & 1) << pixel_index
output += chr(c)
# Red byte
output += '\xFF'
for bit_index in range(7, 0, -1):
c = 0x00
for pixel_index in range(0, 8):
- c |= (ord(data[3*pixel_index]) >> bit_index & 1) << pixel_index
+ c |= (data[3*pixel_index] >> bit_index & 1) << pixel_index
output += chr(c)
# Blue byte
output += '\xFF'
for bit_index in range(7, 0, -1):
c = 0x00
for pixel_index in range(0, 8):
- c |= (ord(data[2+3*pixel_index]) >> bit_index & 1) << pixel_index
+ c |= (data[2+3*pixel_index] >> bit_index & 1) << pixel_index
output += chr(c)

0 comments on commit 67a6e73

Please sign in to comment.