Esempio n. 1
0
 def set_left_led(self, color: Color):
     """Changes the color of the LED on RVR's left side (which is the side with RVR's battery bay door). Set this
     using RGB (red, green, blue) values on a scale of 0 - 255. For example, the green color is expressed as
     ``set_left_led(Color(0, 255, 34))``."""
     if isinstance(self.__toy, RVR):
         self.__leds['left'] = bound_color(color, self.__leds['left'])
         ToyUtil.set_battery_side_led(self.__toy, **self.__leds['left']._asdict())
Esempio n. 2
0
 def set_right_led(self, color: Color):
     """Changes the color of the LED on RVR's right side (which is the side with RVR's power button). Set this using
     RGB (red, green, blue) values on a scale of 0 - 255. For example, the red color is expressed as
     ``set_right_led(Color(255, 18, 0))``."""
     if isinstance(self.__toy, RVR):
         self.__leds['right'] = bound_color(color, self.__leds['right'])
         ToyUtil.set_power_side_led(self.__toy, **self.__leds['right']._asdict())
Esempio n. 3
0
 def set_right_headlight_led(self, color: Color):
     """Changes the color of the front right headlight LED on RVR. Set this using RGB (red, green, blue) values on a
     scale of 0 - 255. For example, the blue color is expressed as
     ``set_right_headlight_led(0, 28, 255)``."""
     if isinstance(self.__toy, RVR):
         self.__leds['right_headlight'] = bound_color(color, self.__leds['right_headlight'])
         ToyUtil.set_right_front_led(self.__toy, **self.__leds['right_headlight']._asdict())
Esempio n. 4
0
    def fade(self, from_color: Color, to_color: Color, duration: float):
        """Changes the main LED lights from one color to another over a period of seconds. For example, to fade from
        green to blue over 3s, use: ``fade(Color(0, 255, 0), Color(0, 0, 255), 3.0)``."""
        from_color = bound_color(from_color, self.__leds['main'])
        to_color = bound_color(to_color, self.__leds['main'])

        start = time.time()
        while True:
            frac = (time.time() - start) / duration
            if frac >= 1:
                break
            self.set_main_led(Color(
                r=round(from_color.r * (1 - frac) + to_color.r * frac),
                g=round(from_color.g * (1 - frac) + to_color.g * frac),
                b=round(from_color.b * (1 - frac) + to_color.b * frac)))
        self.set_main_led(to_color)
Esempio n. 5
0
 def set_main_led(self, color: Color):
     """Changes the color of the main LED light, or the full matrix on Sphero BOLT. Set this using RGB
     (red, green, blue) values on a scale of 0 - 255. For example, ``set_main_led(Color(r=90, g=255, b=90))``."""
     self.__leds['main'] = bound_color(color, self.__leds['main'])
     ToyUtil.set_main_led(self.__toy,
                          **self.__leds['main']._asdict(),
                          is_user_color=False)
Esempio n. 6
0
    def set_front_led(self, color: Color):
        """For Sphero RVR: Changes the color of RVR's front two LED headlights together.

        For Sphero BOLT, R2D2, R2Q5: Changes the color of the front LED light.

        Set this using RGB (red, green, blue) values on a scale of 0 - 255. For example, the magenta color is expressed
        as ``set_front_color(Color(239, 0, 255))``."""
        if isinstance(self.__toy, (R2D2, R2Q5, BOLT, RVR)):
            self.__leds['front'] = bound_color(color, self.__leds['front'])
            ToyUtil.set_front_led(self.__toy, **self.__leds['front']._asdict())
Esempio n. 7
0
    def set_back_led(self, color: Union[Color, int]):
        """For older Sphero:
        Sets the brightness of the back aiming LED, aka the "Tail Light." This LED is limited to blue only, with a
        brightness scale from 0 to 255. For example, use ``set_back_led(255)`` to set the back LED to full brightness.
        Use :func:`time.sleep` to set it on for a duration. For example, to create a dim and a bright blink
        sequence use::

            set_back_led(0)  # Dim
            delay(0.33)
            set_back_led(255)  # Bright
            delay(0.33)

        For Sphero BOLT, R2D2, R2Q5:
        Changes the color of the back LED light. Set this using RGB (red, green, blue) values on a scale of 0 - 255.

        For Sphero RVR:
        Changes the color of the left and right breaklight LED light. Set this using RGB (red, green, blue) values
        on a scale of 0 - 255."""
        if isinstance(color, int):
            self.__leds['back'] = Color(0, 0, bound_value(0, color, 255))
            ToyUtil.set_back_led_brightness(self.__toy, self.__leds['back'].b)
        elif isinstance(self.__toy, (R2D2, R2Q5, BOLT, RVR)):
            self.__leds['back'] = bound_color(color, self.__leds['back'])
            ToyUtil.set_back_led(self.__toy, **self.__leds['back']._asdict())