21 GPIO.output(self.__clk_pin, GPIO.LOW)
22 time.sleep(0.00002)
23 GPIO.output(self.__clk_pin, GPIO.HIGH)
24 time.sleep(0.00002)
25
26 def sendByte(self, b):
27 "Send one bit at a time, starting with the MSB"
28 for i in range(8):
29 # If MSB is 1, write one and clock it, else
30 if (b & 0x80) != 0:
31 GPIO.output(self.__data_pin, GPIO.HIGH)
32 else:
33 GPIO.output(self.__data_pin, GPIO.LOW)
34 self.clk()
35
36 # Advance to the next bit to send
37 b = b << 1
38
39 def sendColor(self, red, green, blue):
40 "Start by sending a byte with the format '1 1 /
41 #prefix = B11000000
42 prefix = 0xC0
43 if (blue & 0x80) == 0:
44 #prefix |= B00100000
45 prefix |= 0x20
46 if (blue & 0x40) == 0:
47 #prefix |= B00010000
48 prefix |= 0x10
49 if (green & 0x80) == 0:
50 #prefix |= B00001000
51 prefix |= 0x08
52 if (green & 0x40) == 0:
53 #prefix |= B00000100
54 prefix |= 0x04
55 if (red & 0x80) == 0:
56 #prefix |= B00000010
57 prefix |= 0x02
58 if (red & 0x40) == 0:
59 #prefix |= B00000001
60 prefix |= 0x01
61 self.sendByte(prefix)