From d913fdf9a632d9a3802831eadee838117b7f63fe Mon Sep 17 00:00:00 2001 From: footleg Date: Wed, 28 Dec 2022 21:16:10 +0000 Subject: [PATCH] Implemented changes to getPixel from code review --- neopixel.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/neopixel.py b/neopixel.py index 2e6a0b6..6bb00a4 100644 --- a/neopixel.py +++ b/neopixel.py @@ -199,21 +199,20 @@ class Neopixel: else: self.pixels[pixel_num] = pix_value - def get_pixelRGB(self, pixel_num): + def get_pixel(self, pixel_num): """ - Get red, green and blue value of pixel on position + Get red, green, blue and white (if applicable) values of pixel on position - :param pixel_num: Index of pixel to be set or slice object representing multiple leds + :param pixel_num: Index of pixel to be set :return rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used """ balance = self.pixels[pixel_num] + sh_R, sh_G, sh_B, sh_W = self.shift if self.W_in_mode: - w = balance & 255 - balance = (balance-w) >> 8 - b = balance & 255 - balance = (balance-b) >> 8 - r = balance & 255 - g = ((balance-r) >> 8) & 255 + w = (balance >> sh_W) & 255 + b = (balance >> sh_B) & 255 + r = (balance >> sh_R) & 255 + g = (balance >> sh_G) & 255 red = int(r * 255 / self.brightness() ) green = int(g * 255 / self.brightness() ) blue = int(b * 255 / self.brightness() ) @@ -349,4 +348,4 @@ class Neopixel: :return: None """ - self.pixels = array.array("I", [0] * self.num_leds) + self.pixels = array.array("I", [0] * self.num_leds) \ No newline at end of file