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 __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 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 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 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 __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 __init__(self): self.BUTTON = Button( pin=11, ) GPIO.setup( self.WAITING_PIN, GPIO.OUT, ) self.LCD = LCD( pin_rs=4, pin_e=25, pins_d=[24,23,22,27], ) self.TRAFFIC = Traffic( pin_red=14, pin_amber=3, pin_green=2, lcd=self.LCD, lcd_line=2, ) self.RGB = RGB( pin_red=9, pin_green=10, pin_blue=15, lcd=self.LCD, lcd_line=3, ) self.RGB.show_colour(self.RGB_MAX, self.RGB_MIN, self.RGB_MIN)
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 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 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): 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 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 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 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 __init__(self, x, y): self.ORIGINAL_WIDTH = 2 * windowManager.horizontalScale self.width = 2 * windowManager.horizontalScale self.ORIGINAL_HEIGHT = 15 * windowManager.verticalScale self.height = 15 * windowManager.verticalScale self.ORIGINAL_X = x - (self.width / 2) self.startX = x - (self.width / 2) self.ORIGINAL_Y = y self.startY = y self.physics = Physics(self.startX, self.startY) self.physics.maxSpeed = Vector(15*windowManager.horizontalScale, 15*windowManager.verticalScale) self.physics.weight = Vector(0, 0) self.physics.floorItSpeed = Vector(15*windowManager.horizontalScale, 15*windowManager.verticalScale) self.color = RGB(255, 0, 255) # Pink self.canvasItem = canvasManager.canvas.create_rectangle(self.physics.location.x, self.physics.location.y, self.physics.location.x+self.width, self.physics.location.y+self.height, fill=self.color.hex())
def __init__(self, x, y): self.ORIGINAL_WIDTH = 20 self.width = 20 self.ORIGINAL_HEIGHT = 20 self.height = 20 self.ORIGINAL_HALF_SHIP_WIDTH = self.width / 2 self.halfShipWidth = self.width / 2 self.ORIGINAL_X = x - self.halfShipWidth self.startX = x - self.halfShipWidth self.ORIGINAL_Y = y - 40 self.startY = y - 40 self.physics = Physics(self.startX, self.startY) self.color = RGB(0, 255, 0) # Green self.adjustHealthBy(0) self.canvasItem = canvasManager.canvas.create_polygon(self.physics.location.x, self.physics.location.y, self.physics.location.x+self.halfShipWidth, self.physics.location.y-self.height, self.physics.location.x+self.width, self.physics.location.y, fill=self.color.hex())
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 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) # 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() # you learned in first grade, red and green make... huh? time.sleep(1) # extra spicy (optional) part myRGB1.rainbow() # Fade through the colors of the rainbow at the given rate. Oooooh, pretty! myRGB2.rainbow() # Fade through the colors of the rainbow at the given rate. Oooooh, pretty! time.sleep(1)
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 from rgb import RGB # import the RGB class from the rgb module r1 = board.D3 g1 = board.D4 b1 = board.D5 r2 = board.D9 g2 = board.D7 b2 = board.D8 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) # 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)
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):
class Ship(Entity): halfShipWidth = -1 bulletPath = {Actions.UP : True, Actions.DOWN : False, Actions.LEFT: False, Actions.RIGHT: False, Actions.SPACE: False, Actions.QUIT: False} bulletTimer = 0 BULLET_WAIT_TIME = 5 ORIGINAL_HALF_SHIP_WIDTH = 0 def __init__(self, x, y): self.ORIGINAL_WIDTH = 20 self.width = 20 self.ORIGINAL_HEIGHT = 20 self.height = 20 self.ORIGINAL_HALF_SHIP_WIDTH = self.width / 2 self.halfShipWidth = self.width / 2 self.ORIGINAL_X = x - self.halfShipWidth self.startX = x - self.halfShipWidth self.ORIGINAL_Y = y - 40 self.startY = y - 40 self.physics = Physics(self.startX, self.startY) self.color = RGB(0, 255, 0) # Green self.adjustHealthBy(0) self.canvasItem = canvasManager.canvas.create_polygon(self.physics.location.x, self.physics.location.y, self.physics.location.x+self.halfShipWidth, self.physics.location.y-self.height, self.physics.location.x+self.width, self.physics.location.y, fill=self.color.hex()) # Override def calculateNewLocationBasedOnActions(self, requestedActions): if self.bulletTimer < self.BULLET_WAIT_TIME: self.bulletTimer += 1 if requestedActions[Actions.SPACE]: if self.bulletTimer >= self.BULLET_WAIT_TIME: newBullet = StandardBullet(self.physics.location.x+self.halfShipWidth, self.physics.location.y-self.height) newBullet.bulletPath = self.bulletPath gameManager.bullets.append (newBullet) self.bulletTimer = 0 return super(Ship, self).calculateNewLocationBasedOnActions(requestedActions) # Override def scale(self, horizontalScale, verticalScale): self.halfShipWidth = self.ORIGINAL_HALF_SHIP_WIDTH * horizontalScale super(Ship, self).scale(horizontalScale, verticalScale) # Override def drawElement(self): canvasManager.canvas.coords(self.canvasItem, self.physics.location.x, self.physics.location.y, self.physics.location.x+self.halfShipWidth, self.physics.location.y-self.height, self.physics.location.x+self.width, self.physics.location.y)
# 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?
def test_green(): GPIO.setmode(GPIO.BCM) cross_light = RGB(**CROSS_LIGHT_PINS) cross_light.green() while True: pass
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()
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()
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)
class Super(object): def __init__(self): self.BUTTON = Button( pin=11, ) GPIO.setup( self.WAITING_PIN, GPIO.OUT, ) self.LCD = LCD( pin_rs=4, pin_e=25, pins_d=[24,23,22,27], ) self.TRAFFIC = Traffic( pin_red=14, pin_amber=3, pin_green=2, lcd=self.LCD, lcd_line=2, ) self.RGB = RGB( pin_red=9, pin_green=10, pin_blue=15, lcd=self.LCD, lcd_line=3, ) self.RGB.show_colour(self.RGB_MAX, self.RGB_MIN, self.RGB_MIN) def update(self): self._update_lcd() self._update_button() self._update_traffic() self._update_rgb() LCD_LAST_TIME = '' def _update_lcd(self): # Show the current time lcd_time = datetime.now().strftime('%H:%M:%S %d/%m/%y') if lcd_time != self.LCD_LAST_TIME: self.LCD_LAST_TIME = lcd_time self.LCD.output_line(lcd_time, 0) WAITING_PIN = 8 PREV_WAIT_STATE = None def _update_button(self): if self.BUTTON.was_pushed(): self.TRAFFIC.push_the_button() wait_state = self.TRAFFIC.is_waiting if wait_state != self.PREV_WAIT_STATE: if wait_state: self.LCD.output_line('Waiting...', 1) else: self.LCD.output_line('', 1) GPIO.output( self.WAITING_PIN, wait_state, ) self.PREV_WAIT_STATE = wait_state def _update_traffic(self): # Make the traffic lights work self.TRAFFIC.update() RGB_MIN = 0.0 RGB_MAX = 100.0 RGB_STEP = 0 RGB_STEPS = ( (RGB_MAX, RGB_MIN, RGB_MIN), (RGB_MAX, RGB_MAX, RGB_MIN), (RGB_MIN, RGB_MAX, RGB_MIN), (RGB_MIN, RGB_MAX, RGB_MAX), (RGB_MIN, RGB_MIN, RGB_MAX), (RGB_MAX, RGB_MIN, RGB_MAX), ) def _update_rgb(self): # Make a rainbow # If the current step is finished, move to the next if not self.RGB.goto_colour_active: # Show the next step self.RGB_STEP = (self.RGB_STEP + 1) % len(self.RGB_STEPS) self.RGB.goto_colour(*self.RGB_STEPS[self.RGB_STEP]) # But always update self.RGB.update()