示例#1
0
    def set_brightness(self, brightness):
        """
        Set the NeoPixel's global brightness, 0-255.

        :param int brightness:    brightness to set (0-255)
        """
        SPI.command(CMD_NEO_SETBRIGHT, params=[brightness])
示例#2
0
    def init(self, num_leds):
        """
        Initialize the NeoPixel library.

        :param int num_leds:    number of neopixel leds.
        """
        SPI.command(CMD_NEO_INIT, params=[num_leds])
示例#3
0
    def set_all_hsv(self, h, s, v):
        """
        Set the HSV color of the entire strip.

        :param int h:       hue color value (0-255)
        :param int s:       saturation color value (0-255)
        :param int v:       value color value (0-255)
        """
        SPI.command(CMD_NEO_SETALLHSV, params=[h, s, v])
示例#4
0
    def set_all(self, r, g, b):
        """
        Set the color of the entire strip.

        :param int r:       red color value (0-255)
        :param int g:       green color value (0-255)
        :param int b:       blue color value (0-255)
        """
        SPI.command(CMD_NEO_SETALL, params=[r, g, b])
示例#5
0
    def write8(self, addr, reg, data):
        """
        Write a Byte to an I2C device.

        :param int addr:    address of the I2C device.
        :param int reg:     register address in the I2C device
        :param var data:    Byte to send
        """
        SPI.command(CMD_I2C_WRITE8, params=[addr, reg, data])
示例#6
0
    def set_pixel(self, pixel, r, g, b):
        """
        Set the color of a single pixel.

        :param int pixel:   pixel index
        :param int r:       red color value (0-255)
        :param int g:       green color value (0-255)
        :param int b:       blue color value (0-255)
        """
        SPI.command(CMD_NEO_SET, params=[pixel, r, g, b])
示例#7
0
    def set_pixel_hsv(self, pixel, h, s, v):
        """
        Set the HSV color of a single pixel.

        :param int pixel:   pixel index
        :param int h:       hue color value (0-255)
        :param int s:       saturation color value (0-255)
        :param int v:       value color value (0-255)
        """
        SPI.command(CMD_NEO_SETHSV, params=[pixel, h, s, v])
示例#8
0
    def set_range(self, start, end, r, g, b):
        """
        Set the color of a range of pixels.

        :param int start:   start index of led range
        :param int end:     end index of led range
        :param int r:       red color value (0-255)
        :param int g:       green color value (0-255)
        :param int b:       blue color value (0-255)
        """
        SPI.command(CMD_NEO_SETRANGE, params=[start, end, r, g, b])
示例#9
0
    def set_range_hsv(self, start, end, h, s, v):
        """
        Set the HSV color of a range of pixels.

        :param int start:   start index of led range
        :param int end:     end index of led range
        :param int h:       hue color value (0-255)
        :param int s:       saturation color value (0-255)
        :param int v:       value color value (0-255)
        """
        SPI.command(CMD_NEO_SETRANGEHSV, params=[start, end, h, s, v])
示例#10
0
文件: servo.py 项目: Feestig/ONORobot
    def set(self, channel, pos):
        """
        Set the position of one servo.
        Pos in us, 500 to 2500

        :param int channel: channel of the servo
        :param int pos:     position of the servo (500 to 2500)
        """
        offtime = (pos + 2) // 4
        SPI.command(CMD_SERVO_SET,
                    params=[channel, offtime >> 8, offtime & 0x00FF],
                    delay=0.008)
示例#11
0
    def write16(self, addr, reg, data):
        """
        Write 2 bytes to an I2C device.

        :param int addr:    address of the I2C device.
        :param int reg:     register address in the I2C device
        :param var data:    Bytes to send
        """
        val1 = (data & 0xFF00) >> 8
        val2 = (data & 0x00FF)

        SPI.command(CMD_I2C_WRITE16, params=[addr, reg, val1, val2])
示例#12
0
    def detect(self, addr):
        """
        Returns True if an I2C device is found at a particular address.

        :param int addr:   address of the I2C device.

        :return:         I2C device detected
        :rtype:          bool
        """
        return SPI.command(CMD_I2C_DETECT, params=[addr], returned=1)[0] == 1
示例#13
0
文件: servo.py 项目: Feestig/ONORobot
    def set_all(self, pos_list):
        """
        Set position of all 16 servos using a list.

        :param list pos_list:   list of servo positions
        """
        spi_params = []
        i = 0
        for pos in pos_list:
            if pos is None:
                # Tell FW not to update this servo
                spi_params.append(0xFF)
                spi_params.append(0xFF)
            else:
                offtime = (pos + 2) // 4
                spi_params.append(offtime >> 8)
                spi_params.append(offtime & 0x0FF)
            i = i + 1

        SPI.command(CMD_SERVO_SETALL, params=spi_params, delay=0.008)
示例#14
0
    def read8(self, addr, reg):
        """
        Read a Byte from an I2C device.

        :param int addr:    address of the I2C device.
        :param int reg:     register address in the I2C device

        :return:         what is the function returning?
        :rtype:          var
        """
        return SPI.command(CMD_I2C_READ8, params=[addr, reg], returned=1)[0]
示例#15
0
    def read_channel(self, channel):
        """
        Reads the value of a single analog channel.

        :param int channel:     analog channel to read

        :return:         analog value of the channel
        :rtype:          var
        """
        data = SPI.command(CMD_ANA_GET, params=[channel], returned=2)
        return data[0] << 8 | data[1]
示例#16
0
    def read_all_channels(self):
        """
        Reads all analog channels and returns them as a list.

        :return:         analog values
        :rtype:          list
        """
        data = SPI.command(CMD_ANA_GETALL, returned=2)
        return [
            data[0] << 8 | data[1], data[2] << 8 | data[3],
            data[4] << 8 | data[5], data[6] << 8 | data[7]
        ]
示例#17
0
    def read16(self, addr, reg):
        """
        Read 2 bytes from an I2C device.

        :param int addr:    address of the I2C device.
        :param int reg:     register address in the I2C device

        :return:         2 Bytes
        :rtype:          var
        """
        data = SPI.command(CMD_I2C_READ16, params=[addr, reg], returned=2)
        return (data[0] << 8) | data[1]
示例#18
0
文件: servo.py 项目: Feestig/ONORobot
 def init(self):
     """Set up the PCA9685 for driving servos."""
     SPI.command(CMD_SERVO_INIT, delay=0.02)
示例#19
0
文件: servo.py 项目: Feestig/ONORobot
 def enable(self):
     """Turns on the servo power MOSFET, enabling all servos."""
     SPI.command(CMD_SERVO_ENABLE)
示例#20
0
文件: servo.py 项目: Feestig/ONORobot
 def disable(self):
     """Turns off the servo power MOSFET, disabling all servos."""
     SPI.command(CMD_SERVO_DISABLE)
示例#21
0
文件: servo.py 项目: Feestig/ONORobot
 def neutral(self):
     """Set all servos to 1500us."""
     SPI.command(CMD_SERVO_NEUTRAL, delay=0.008)
示例#22
0
 def show(self):
     """Sends the pixel data from the ATmega328 to the NeoPixels."""
     SPI.command(CMD_NEO_SHOW)
示例#23
0
 def disable(self):
     """
 	Turns off the NeoPixel MOSFET, disabling the NeoPixels.
 	Data is lost when pixels are disabled.
 	"""
     SPI.command(CMD_NEO_DISABLE)
示例#24
0
 def enable(self):
     """
 	Turns on the NeoPixel MOSFET, enabling the NeoPixels.
 	Data is lost when pixels are disabled, so call show() again afterwards.
 	"""
     SPI.command(CMD_NEO_ENABLE)