def __init__(self): GPIO.setmode(GPIO.BCM) self.main_light = RGB(**MAIN_LIGHT_PINS) self.cross_light = RGB(**CROSS_LIGHT_PINS) self.display = DigitDisplay(DISPLAY_PINS) self.button = Button(BUTTON_PIN, BOUNCE_TIME, self.handled_press) self.S1()
def mifify(cls, im: Image.Image, color_mif: Mif) -> Mif: width = num_bits_needed(color_mif.get_num_entries()) ret = Mif(width=width) for pixel in im.getdata(): r, g, b = pixel color_dex = color_mif.index_of(RGB(r=r, b=b, g=g)) if color_dex < 0: color_dex = color_mif.index_of( color_mif.get_closest(RGB(r=r, b=b, g=g))) ret.add(MifEntry(value=color_dex, width=width)) return ret
def heat_to_rgb(temperature): t192 = round((temperature / 255.0) * 191) heatramp = t192 & 0x3F heatramp <<= 2 if t192 > 0x80: return RGB(r=255, g=255, b=heatramp, a=255) elif t192 > 0x40: return RGB(r=255, g=heatramp, b=0, a=255) else: return RGB(r=heatramp, g=0, b=0, a=255)
def update_rgba(self): """ Update RGBA values taking them from the database :return: """ # get data from db rgba = self.get("RGBA") # extract values r = rgba.get("r") g = rgba.get("g") b = rgba.get("b") a = rgba.get("a") # convert them to ints r = floor_int(r) g = floor_int(g) b = floor_int(b) a = floor_int(a) # update attr self.rgba = RGB(r=r, g=g, b=b, a=a) # extract random value and convert to bool random = rgba.get("random") == "true" # if method is called before pattern initialization skip try: # update pattern values self.pattern.update_args(randomize_color=random) self.pattern.update_args(color=self.rgba) except AttributeError: pass
def __init__(self, handler, rate, pixels, color=RGB()): """ :param handler: The handler for the led strip, either a DotStar_Emulator.emulator.send_test_data.App or a rpi.pi_handler.PiHandler :param rate:(float) the rate for the pixel update :param pixels: (int) the number of pixels :param color: (default RGB), the initial color for the leds """ rate /= RATE_DIVISOR # init the thread and the handler threading.Thread.__init__(self) self.handler = handler(pixels) self.rate = rate self.strip_length = pixels self.color = color # boolan value to randomize color self.randomize_color = False # string for patter name self.pattern_name = None # dictionary storing the modifiers to be implemented in the web app self.modifiers = dict() # init and set the pixels to the default color self.pixels = { idx: dict(color=self.color) for idx in range(self.strip_length + 1) } self.set_pixels()
def gen(self, header, llvm_dir, dynlib=None, out_file=None, call_con='cdecl', include_dir='.', debug=False): """ Generate a Red/System binding file from the given header input. Args: header(str): the header to parse. llvm_dir(str): the binary directory where LLVM lives dynlib(str): the dynamic library target, used in the outfile out_file(str): the path/name.ext of the output file call_con(str): the calling convention of the library include_dir(str): where other include files are, same as C debug(bool): whether verbose debugging should occur """ # Clean up the header file and obtain all declarations/pound defines declarations = format.format_header(header, llvm_dir, include_dir) # Fix null dynamic lib name if dynlib == None: # Since the extension doesn't matter, just add a dot to it dynlib = os.path.basename(header).split('.')[0] + '.' # Both parse and generate the declarations rgb_compiler = RGB(declarations, dynlib, call_con, out_file) rgb_compiler.compile()
def fill(self): r_phi = self.r_phi b_phi = self.b_phi g_phi = self.g_phi if not self.r_phi == 0: r_phi = pi / self.r_phi if not self.b_phi == 0: b_phi = pi / self.b_phi if not self.g_phi == 0: g_phi = pi / self.g_phi for idx in range(self.strip_length): idx2degree = scale(idx + self.counter, 0, self.max_range, 0, self.strip_length) r = sin(idx2degree + r_phi) g = sin(idx2degree + g_phi) b = sin(idx2degree + b_phi) r = scale(r, 0, 255, -1, 1) g = scale(g, 0, 255, -1, 1) b = scale(b, 0, 255, -1, 1) r = floor(r) g = floor(g) b = floor(b) self.pixels[idx]['color'] = RGB(r=r, g=g, b=b, a=self.color.a) self.counter += 1 self.counter %= self.strip_length * 255
def led_loop(q, baseClock): rgb = RGB(baseClock) sa = StreamAnimation(rgb) while True: if q.qsize() > 0: type = q.get(False) # sa.stopAll() if type == "modswitch": sa.banEvent() elif type == "follows": sa.followEvent() elif type == "streamchange": sa.banEvent() elif type == "subscription": sa.subEvent() else: sa.followEvent() else: sa.baseLoop() sa.rgb.wait() sleep(baseClock)
def fill(self): if self.randomize_color: color = RGB(random=True) else: color = self.color for idx in range(self.strip_length): self.pixels[idx]['color'] = self.color
def empty_center(self): """ Return an empty center point as a dict with fields :return: """ if self.randomize_color: default_dict = dict(color=RGB(random=True), alpha=0, delay=randint(0, 100), increasing=True) else: default_dict = dict(color=RGB(rgb=self.color), alpha=0, delay=randint(0, 100), increasing=True) # if there is no start in delay then alpha is maximum if not self.rate_start: default_dict['alpha'] = 255 return default_dict
def __init__(self, **kwargs): super().__init__(**kwargs) self.trail = 5 self.min_space = 3 # min space between trail end and trail start self.counter = 0 self.pattern_name = "Snow" self.color = RGB(white=True) self.modifiers = dict( trail=self.trail, min_space=self.min_space, )
def compress_colors_collective(cls, images: List[Image.Image], limit: int) -> Tuple[Mif, List[Image.Image]]: """ Compress the colors in the images, keeping the desired count across all images :param limit: Maximum allowed colors :param images: Images to compress :return: The resultant color MIF file for the images and the new, color compressed images """ colors = [pix for im in images for pix in im.getdata()] model = Compressor.get_model(colors, limit) colorMif = Mif(width=24) for color in {tuple(x) for x in model.cluster_centers_}: r, g, b = color colorMif.add(RGB(r=int(r), g=int(g), b=int(b))) recolored_images = [Compressor.recolor_image(image, model) for image in images] return colorMif, recolored_images
def cross_light_tests(): cross_light = RGB(**CROSS_LIGHT_PINS) log.debug('cross_light Successfully Setup') log.debug('Turning Red Light on for cross_light') cross_light.red() sleep(2) log.debug('Turning Blue Light on for cross_light') cross_light.blue() sleep(2) log.debug('Turning Green Light on for cross_light') cross_light.green() sleep(2)
def main_light_tests(): main_light = RGB(**MAIN_LIGHT_PINS) log.debug('main_light Successfully Setup') log.debug('Turning Red Light on for main_light') main_light.red() sleep(2) log.debug('Turning Blue Light on for main_light') main_light.blue() sleep(2) log.debug('Turning Green Light on for main_light') main_light.green() sleep(2)
def gen(self, header, llvm_dir, dynlib, out_file=None, call_con='cdecl', include_dir='.'): """ Generate a Red/System binding file from the given header input. """ # Clean up the header file and obtain all declarations/pound defines declarations = format.format_header(header, llvm_dir, include_dir) # Both parse and generate the declarations rgb_compiler = RGB(declarations, dynlib, call_con, out_file) rgb_compiler.compile()
def fill(self): step = self.step color = self.color if self.reverse: color = RGB() for idx in range(self.strip_length): if idx < step: self.pixels[idx]['color'] = color self.step += 1 if self.step > self.strip_length: self.reverse = not self.reverse self.step = 0
def __init__(self, **kwargs): super().__init__(**kwargs) self.counter = 0 self.color = RGB(white=True) self.r_phi = 0 self.b_phi = 1 self.g_phi = 2 self.max_range = 1 self.pattern_name = "Rainbow" self.modifiers = dict( r_phi=self.r_phi, b_phi=self.b_phi, g_phi=self.g_phi, max_range=self.max_range, ) self.set_pixels()
def test_green(): GPIO.setmode(GPIO.BCM) cross_light = RGB(**CROSS_LIGHT_PINS) cross_light.green() while True: pass
# in this code, RGB is the "x" from rgb import RGB # import the RGB class from the rgb module import board import time #below sets up pins for each of the LEDs r1 = board.D2 g1 = board.D3 b1 = board.D4 r2 = board.D5 g2 = board.D7 b2 = board.D1 myRGB1 = RGB(r1, g1, b1) # create a new RGB object, using pins 2, 3, and 4 myRGB2 = RGB(r2, g2, b2) # create a new RGB object, using pins 5, 1, and 7 myRGB1.change_pins(r1, g1, b1) print(myRGB1.kind) print(myRGB2.kind) myRGB1.change_name("rex") print(myRGB1.name) myRGB1.red() # Glow red myRGB2.green() # Glow green time.sleep(1) myRGB1.blue() # Glow blue myRGB2.cyan() # Glow... you get it... time.sleep(1) myRGB1.magenta() # Did you know magenta isn't in the rainbow?
from DotStar_Emulator.emulator.send_test_data import App from patterns import Patterns from rgb import RGB # Available patterns are: # ColorWipe # Fading # Fire # FireWork # Meteor # Rainbow # Snow # Steady # Pulse # Chasing # choose pattern, rate and color pat = Patterns['Music'] rate = 10 color = RGB(random=True) # init app and run app = pat(handler=App, rate=rate, pixels=64, color=color) app.run()
# camera setup camera = picamera.PiCamera() camera.resolution = (image_width, image_height) camera.awb_mode = 'auto' # ['awb_mode'] camera.vflip = True # verify image folder exists and create if it does not if not os.path.exists(image_folder): os.makedirs(image_folder) #For testing send_data = True #Button Settings GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) led = RGB(21, 20, 16) currentTime = datetime.now() print(currentTime) led.redOn() sleep(0.5) led.redOff() tryNumber = table.item_count + 1 print(str(tryNumber)) print("waiting for button") while True: try:
import board #pylint: disable-msg=import-error import time from rgb import RGB #pin numbers for each color r1 = board.D2 g1 = board.D3 b1 = board.D4 r2 = board.D5 g2 = board.D6 b2 = board.D7 #declare objects LED1 = RGB(r1, g1, b1) LED2 = RGB(r2, g2, b2) #call methods from class LED1.red() LED2.green() time.sleep(1) LED1.blue() LED2.cyan() time.sleep(1) LED1.magenta() LED2.yellow() time.sleep(1)
from rgb import RGB # import the RGB class from the rgb module myRGB1 = RGB(2, 3, 4) # create a new RGB object, using pins 2, 3, and 4 myRGB2 = RGB(5, 6, 7) # create a new RGB object, using pins 5, 6, and 7 myRGB1.red() # Glow red myRGB2.green() # Glow green time.sleep(1) myRGB1.blue() # Glow blue myRGB2.cyan() # Glow... you get it... time.sleep(1) myRGB1.magenta() # Did you know magenta isn't in the rainbow? myRGB2.yellow() # Like you learned in first grade, red and green make... huh? time.sleep(1) # extra spicy (optional) part myRGB1.rainbow( rate1 ) # Fade through the colors of the rainbow at the given rate. Oooooh, pretty! myRGB2.rainbow( rate2 ) # Fade through the colors of the rainbow at the given rate. Oooooh, pretty! time.sleep(1)
import time import board #pylint: disable-msg=import-error from rgb import RGB pins1 = [board.D1, board.D2, board.D3] pins2 = [board.D4, board.D5, board.D7] delay = 1 myRGB1 = RGB(pins1) myRGB2 = RGB(pins2) print("go") while True: myRGB1.red() myRGB2.green() time.sleep(delay) myRGB1.green() myRGB2.red() time.sleep(delay) myRGB1.blue() myRGB2.cyan() time.sleep(delay) myRGB1.cyan() myRGB2.blue() time.sleep(delay) myRGB1.magenta() myRGB2.yellow() time.sleep(delay) myRGB1.yellow() myRGB2.magenta()
def on_publish(mosq, obj, mid): print("mid: " + str(mid)) def on_subscribe(mosq, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mosq, obj, level, string): print(string) print("init") # Create RGB object to control the leds rgb = RGB() # Create a periodic task to do the fading fadeTask = PeriodicTask(periodSec=1, task=rgb.fade) # Setup callbacks and the connection to the broker client = paho.Client() client.on_message = on_message client.on_connect = on_connect client.on_publish = on_publish client.on_subscribe = on_subscribe # client.username_pw_set(username="",password="") client.connect("localhost") client.loop_start() while (1):
# generate string representations for entry in self.entries: for key, value in entry[1].items(): entry[0].append('{0}={1}'.format(key, value)) entries.append('\t{' + ', '.join(parse(arg) for arg in entry[0]) + '}') return 'cycle list={\n' + ',\n'.join(entries) + '}' # predefined cycle lists cycle_lists = { 'fancy': CycleList([ { 'color': RGB(10, 80, 230) }, { 'color': RGB(255, 83, 204) }, { 'color': RGB(170, 250, 120) }, { 'color': RGB(0, 0, 0) }, { 'color': RGB(255, 200, 0) }, ]), 'fruity':
def render(self): """ Produces LaTeX code for this plot. @rtype: string @return: LaTeX code for this plot """ options = [] marker_options = [] error_options = [] if not self.axes.cycle_list and not self.axes.cycle_list_name: # default settings marker_options.append('solid') if not self.marker: options.append('no marks') elif not self.line_style: options.append('only marks') # basic properties if self.line_style: options.append(self.line_style) if self.line_width is not None: options.append('line width={0}pt'.format(self.line_width)) if isinstance(self.color, RGB): options.append('color={0}'.format(self.color)) elif isinstance(self.color, str): options.append(self.color) if self.fill: if isinstance(self.fill, str) or isinstance(self.fill, RGB): options.append('fill={0}'.format(self.fill)) elif hasattr(self.fill, '__len__') and len(self.fill) == 3: print self.fill options.append('fill={0}'.format(RGB(*self.fill))) else: options.append('fill') if self.opacity is not None: options.append('opacity={0}'.format(self.opacity)) if self.marker: options.append('mark={0}'.format(replace(self.marker, '.', '*'))) # marker properties if self.marker_edge_color: marker_options.append(str(self.marker_edge_color)) if self.marker_face_color: marker_options.append('fill={0}'.format(self.marker_face_color)) if self.marker_size is not None: marker_options.append('scale={0}'.format(self.marker_size)) if self.marker_opacity is not None: if self.opacity is not None: marker_options.append('opacity={0}'.format(self.opacity)) marker_options.append('fill opacity={0}'.format( self.marker_opacity)) elif self.opacity is not None: marker_options.append('fill opacity={0}'.format(self.opacity)) if marker_options: options.append('mark options={{{0}}}'.format( ', '.join(marker_options))) # custom properties options.extend(list(self.pgf_options)) # PGF pattern if self.pattern: options.append('pattern={{{0}}}'.format(self.pattern)) # error bar properties if len(self.xvalues_error) or len(self.yvalues_error): options.append('error bars/.cd') if len(self.xvalues_error): options.append('x dir=both') options.append('x explicit') if len(self.yvalues_error): options.append('y dir=both') options.append('y explicit') if self.error_marker: options.append('error mark={0}'.format(self.error_marker)) if self.error_color: error_options.append('color={0}'.format(self.error_color)) if self.error_style: error_options.append(self.error_style) if self.error_width: error_options.append('line width={0}pt'.format(self.error_width)) if error_options: options.append('error bar style={{{0}}}'.format( ', '.join(error_options))) # comb plots if self.ycomb: options.append('ycomb') elif self.xcomb: options.append('xcomb') # linear interpolation if self.const_plot: options.append('const plot') if self.labels: options.append('nodes near coords') options.append('point meta=explicit symbolic') # summarize options into one string options_string = ', '.join(options) if len(options_string) > 70: options_string = '\n' + indent(',\n'.join(options)) tex = '% ' + self.comment + '\n' if self.comment else '' if options_string: tex += '\\addplot+[{0}] coordinates {{\n'.format(options_string) else: tex += '\\addplot coordinates {\n' if len(self.xvalues_error) or len(self.yvalues_error): x_error = self.xvalues_error if len(self.xvalues_error) \ else zeros(shape(self.yvalues_error)) y_error = self.yvalues_error if len(self.yvalues_error) \ else zeros(shape(self.xvalues_error)) # render plot with error bars for x, y, e, f in zip(self.xvalues, self.yvalues, x_error, y_error): tex += '\t({0}, {1}) +- ({2}, {3})\n'.format(x, y, e, f) else: # render plot coordinates if self.labels: for x, y, l in zip(self.xvalues, self.yvalues, self.labels): tex += '\t({0}, {1}) [{2}]\n'.format(x, y, l) else: for x, y in zip(self.xvalues, self.yvalues): tex += '\t({0}, {1})\n'.format(x, y) if self.closed: tex += '} \\closedcycle;\n' else: tex += '};\n' if self.legend_entry is not None: tex += '\\addlegendentry{{{0}}};\n'.format( self.legend_entry.replace('_', '\\_')) return tex
import time import board from rgb import RGB # import the RGB class from the rgb module r1 = board.D3 g1 = board.D4 b1 = board.D5 r2 = board.D8 g2 = board.D9 b2 = board.D10 myRGB1 = RGB(r1, g1, b1) myRGB2 = RGB(r2, g2, b2) myRGB1.red() myRGB2.green() myRGB1.blue() myRGB2.cyan() time.sleep(1) myRGB1.magenta() myRGB2.yellow() time.sleep(1)
import time import board from rgb import RGB # import the RGB class from the rgb module r1 = board.D3 #sets all pins up g1 = board.D4 b1 = board.D5 r2 = board.D1 g2 = board.D2 b2 = board.D7 myRGB1 = RGB(r1, g1, b1) # create a new RGB object, using pins 3, 4, and 5 myRGB2 = RGB(r2, g2, b2) # create a new RGB object, using pins 8, 9, and 10 myRGB1.red() # Glow red myRGB2.green() # Glow green time.sleep(1) myRGB1.blue() # Glow blue myRGB2.cyan() # Glow... you get it... time.sleep(1) myRGB1.magenta() # Did you know magenta isn't in the rainbow? myRGB2.yellow() # Like you learned in first grade, red and green make... huh? time.sleep(1) myRGB1.rainbow1( ) # Nicely fade through all the colors of the rainbow at the given rate. Oooooh, pretty! myRGB2.rainbow2( ) # Nicely fade through all the colors of the rainbow at the given rate. Oooooh, pretty! time.sleep(1)
import time import board #pylint: disable-msg=import-error from rgb import RGB r = board.D2 g = board.D3 b = board.D4 myRGB = RGB(r, g, b) print("go") while True: myRGB.red() time.sleep(0.1) myRGB.green() time.sleep(0.1) myRGB.blue() time.sleep(0.1) myRGB.cyan() time.sleep(0.1) myRGB.magenta() time.sleep(0.1) myRGB.yellow() time.sleep(0.1) myRGB.white() time.sleep(0.1) myRGB.black() time.sleep(0.1) myRGB.rainbow()