Пример #1
0
test_drives = False
test_speaker = False

counter = 0

#analog_out = AnalogOut(board.A0)
#analog_out.value = 512

while True:
    counter = (counter + 1) % 256

    if counter % 32 == 0:
        print("-------------------- analog -----------------------")
        str_out = ""
        for i in range(8):
            val = ss.analog_read(CRCKit_adc[i]) * 3.3 / 1024
            str_out = str_out + str(round(val, 2)) + "\t"

        print(str_out + "\n")

    for i in range(4):
        val = ss.touch_read(i)
        cap_justtouched[i] = False
        cap_justreleased[i] = False

        if val > CAPTOUCH_THRESH:
            print("CT" + str(i + 1) + " touched! value: " + str(val))

            if not cap_state[i]:
                cap_justtouched[i] = True
Пример #2
0
                    | (1 << BUTTON_DOWN)
                    | (1 << BUTTON_LEFT)
                    | (1 << BUTTON_UP)
                    | (1 << BUTTON_SEL))

i2c_bus = busio.I2C(SCL, SDA)

ss = Seesaw(i2c_bus)

ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)

last_x = 0
last_y = 0

while True:
    x = ss.analog_read(2)
    y = ss.analog_read(3)

    if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
        print(x, y)
        last_x = x
        last_y = y

    buttons = ss.digital_read_bulk(button_mask)
    if not buttons & (1 << BUTTON_RIGHT):
        print("Button A pressed")

    if not buttons & (1 << BUTTON_DOWN):
        print("Button B pressed")

    if not buttons & (1 << BUTTON_LEFT):
class MonsterM4sk:
    """Class representing a `MONSTER M4SK`
           <https://www.adafruit.com/product/4343>`_.

            The terms "left" and "right" are always used from the
            perspective of looking out of the mask.
            The right screen is the one USB port directly above it.
           """
    def __init__(self, i2c=None):
        displayio.release_displays()

        if i2c is None:
            i2c = board.I2C()

        # set up on-board seesaw
        self._ss = Seesaw(i2c)
        # left screen
        self._ss.pin_mode(SS_TFTRESET_PIN, self._ss.OUTPUT)
        self._ss.pin_mode(SS_SWITCH1_PIN, self._ss.INPUT_PULLUP)
        self._ss.pin_mode(SS_SWITCH2_PIN, self._ss.INPUT_PULLUP)
        self._ss.pin_mode(SS_SWITCH3_PIN, self._ss.INPUT_PULLUP)

        self._ss.pin_mode(SS_LIGHTSENSOR_PIN, self._ss.INPUT)

        # Manual reset for left screen
        self._ss.digital_write(SS_TFTRESET_PIN, False)
        time.sleep(0.01)
        self._ss.digital_write(SS_TFTRESET_PIN, True)
        time.sleep(0.01)

        # Left backlight pin, on the seesaw
        self._ss.pin_mode(SS_BACKLIGHT_PIN, self._ss.OUTPUT)
        # backlight on full brightness
        self._ss.analog_write(SS_BACKLIGHT_PIN, 255)

        # Left screen spi bus
        left_spi = busio.SPI(board.LEFT_TFT_SCK, MOSI=board.LEFT_TFT_MOSI)
        left_tft_cs = board.LEFT_TFT_CS
        left_tft_dc = board.LEFT_TFT_DC

        left_display_bus = displayio.FourWire(left_spi,
                                              command=left_tft_dc,
                                              chip_select=left_tft_cs)

        self.left_display = ST7789(left_display_bus,
                                   width=240,
                                   height=240,
                                   rowstart=80)

        self.right_backlight = pulseio.PWMOut(board.RIGHT_TFT_LITE,
                                              frequency=5000,
                                              duty_cycle=0)
        self.right_backlight.duty_cycle = 65535

        # right display
        right_spi = busio.SPI(board.RIGHT_TFT_SCK, MOSI=board.RIGHT_TFT_MOSI)
        right_tft_cs = board.RIGHT_TFT_CS
        right_tft_dc = board.RIGHT_TFT_DC

        right_display_bus = displayio.FourWire(
            right_spi,
            command=right_tft_dc,
            chip_select=right_tft_cs,
            reset=board.RIGHT_TFT_RST,
        )

        self.right_display = ST7789(right_display_bus,
                                    width=240,
                                    height=240,
                                    rowstart=80)

        if i2c is not None:
            int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
            try:
                self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c,
                                                                 address=0x19,
                                                                 int1=int1)
            except ValueError:
                self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c,
                                                                 int1=int1)

        self.nose = touchio.TouchIn(board.NOSE)
        self.nose.threshold = 180

    @property
    def acceleration(self):
        """Accelerometer data, +/- 2G sensitivity."""
        return (self._accelerometer.acceleration
                if self._accelerometer is not None else None)

    @property
    def light(self):
        """Light sensor data."""
        return self._ss.analog_read(SS_LIGHTSENSOR_PIN)

    @property
    def boop(self):
        """Nose touch sense."""
        return self.nose.value
Пример #4
0
                    (1 << BUTTON_DOWN) |
                    (1 << BUTTON_LEFT) |
                    (1 << BUTTON_UP) |
                    (1 << BUTTON_SEL))

i2c_bus = busio.I2C(SCL, SDA)

ss = Seesaw(i2c_bus)

ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)

last_x = 0
last_y = 0

while True:
    x = ss.analog_read(2)
    y = ss.analog_read(3)

    if  (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
        print(x, y)
        last_x = x
        last_y = y

    buttons = ss.digital_read_bulk(button_mask)
    if not buttons & (1 << BUTTON_RIGHT):
        print("Button A pressed")

    if not buttons & (1 << BUTTON_DOWN):
        print("Button B pressed")

    if not buttons & (1 << BUTTON_LEFT):
Пример #5
0
play_file("only-prescription-more-cowbell.wav")

while seesaw.digital_read(SWITCH):
    pass

print("Ready for playing audio")
time.sleep(1)

f = open("fear11.wav", "rb")
wav = audioio.WaveFile(f)
a.play(wav)

while True:
    if seesaw.digital_read(SWITCH):
        break  # time to bail!
    pot = seesaw.analog_read(MORECOW)
    print(pot)
    eyecolor = (int(map_range(pot, 0, 1023, 255,
                              0)), int(map_range(pot, 0, 1023, 0, 255)), 0)
    pixels[8] = eyecolor
    pixels[7] = eyecolor

    if buttonb.value:
        fog_on.duty_cycle = 65535
    else:
        fog_on.duty_cycle = 0

    if buttona.value:
        fog_off.duty_cycle = 65535
    else:
        fog_off.duty_cycle = 0
Пример #6
0
class MonsterM4sk:
    """Represents a single Monster M4sk

    The terms "left" and "right" are always used from the
    perspective of looking out of the mask.
    The right screen is the one USB port directly above it.
    """

    def __init__(self, i2c=None):
        """
        :param i2c: The I2C bus to use, will try board.I2C()
            if not supplied

        """
        displayio.release_displays()

        if i2c is None:
            i2c = board.I2C()

        # set up on-board seesaw
        self._ss = Seesaw(i2c)

        # set up seesaw pins
        self._ss.pin_mode(SS_TFTRESET_PIN, self._ss.OUTPUT)  # left sceen reset

        # buttons abolve left eye
        self._ss.pin_mode(SS_SWITCH1_PIN, self._ss.INPUT_PULLUP)
        self._ss.pin_mode(SS_SWITCH2_PIN, self._ss.INPUT_PULLUP)
        self._ss.pin_mode(SS_SWITCH3_PIN, self._ss.INPUT_PULLUP)

        # light sensor near left eye
        self._ss.pin_mode(SS_LIGHTSENSOR_PIN, self._ss.INPUT)

        # Manual reset for left screen
        self._ss.digital_write(SS_TFTRESET_PIN, False)
        time.sleep(0.01)
        self._ss.digital_write(SS_TFTRESET_PIN, True)
        time.sleep(0.01)

        # Left backlight pin, on the seesaw
        self._ss.pin_mode(SS_BACKLIGHT_PIN, self._ss.OUTPUT)
        # backlight on full brightness
        self._ss.analog_write(SS_BACKLIGHT_PIN, 255)

        # Left screen spi bus
        left_spi = busio.SPI(board.LEFT_TFT_SCK, MOSI=board.LEFT_TFT_MOSI)
        left_tft_cs = board.LEFT_TFT_CS
        left_tft_dc = board.LEFT_TFT_DC

        left_display_bus = displayio.FourWire(
            left_spi, command=left_tft_dc, chip_select=left_tft_cs  # Reset on Seesaw
        )

        self.left_display = ST7789(left_display_bus, width=240, height=240, rowstart=80)

        # right backlight on board
        self.right_backlight = pulseio.PWMOut(
            board.RIGHT_TFT_LITE, frequency=5000, duty_cycle=0
        )
        # full brightness
        self.right_backlight.duty_cycle = 65535

        # right display spi bus
        right_spi = busio.SPI(board.RIGHT_TFT_SCK, MOSI=board.RIGHT_TFT_MOSI)
        right_tft_cs = board.RIGHT_TFT_CS
        right_tft_dc = board.RIGHT_TFT_DC

        right_display_bus = displayio.FourWire(
            right_spi,
            command=right_tft_dc,
            chip_select=right_tft_cs,
            reset=board.RIGHT_TFT_RST,  # reset on board
        )

        self.right_display = ST7789(
            right_display_bus, width=240, height=240, rowstart=80
        )

        # setup accelerometer
        if i2c is not None:
            int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
            try:
                self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
                    i2c, address=0x19, int1=int1
                )
            except ValueError:
                self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

        # touchio on nose
        self.nose = touchio.TouchIn(board.NOSE)

        # can be iffy, depending on environment and person.
        # User code can tweak if needed.
        self.nose.threshold = 180

    @property
    def acceleration(self):
        """Accelerometer data, +/- 2G sensitivity.

        This example initializes the mask and prints the accelerometer data.

        .. code-block:: python

            import adafruit_monsterm4sk
            mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
            print(mask.acceleration)

        """
        return (
            self._accelerometer.acceleration
            if self._accelerometer is not None
            else None
        )

    @property
    def light(self):
        """Light sensor data.

        This example initializes the mask and prints the light sensor data.

        .. code-block:: python

                import adafruit_monsterm4sk
                mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())
                print(mask.light)

        """
        return self._ss.analog_read(SS_LIGHTSENSOR_PIN)

    @property
    def buttons(self):
        """Buttons dictionary.

        This example initializes the mask and prints when the S9 button
        is pressed down.

        .. code-block:: python

                import adafruit_monsterm4sk
                mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())

                while True:
                    if mask.buttons["S9"]:
                        print("Button S9 pressed!")

        """

        return {
            "S9": self._ss.digital_read(SS_SWITCH1_PIN) is False,
            "S10": self._ss.digital_read(SS_SWITCH2_PIN) is False,
            "S11": self._ss.digital_read(SS_SWITCH3_PIN) is False,
        }

    @property
    def boop(self):
        """Nose touch sense.

        This example initializes the mask and prints when the nose touch pad
        is being touched.

        .. code-block:: python

                import adafruit_monsterm4sk
                mask = adafruit_monsterm4sk.MonsterM4sk(i2c=board.I2C())

                while True:
                    if mask.boop:
                        print("Nose touched!")

        """
        return self.nose.value
Пример #7
0
test_drives = False
test_speaker = False

counter = 0

#analog_out = AnalogOut(board.A0)
#analog_out.value = 512

while True:
    counter = (counter + 1) % 256

    if counter % 32 == 0:
        print("-------------------- analog -----------------------")
        str_out = ""
        for i in range(8):
            val = ss.analog_read(CRCKit_adc[i]) * 3.3/1024
            str_out = str_out + str(round(val, 2)) + "\t"

        print(str_out + "\n")


    for i in range(4):
        val = ss.touch_read(i)
        cap_justtouched[i] = False
        cap_justreleased[i] = False

        if val > CAPTOUCH_THRESH:
            print("CT" + str(i + 1) + " touched! value: " + str(val))

            if not cap_state[i]:
                cap_justtouched[i] = True
# Maps a number from one range to another.
def map_range(x, in_min, in_max, out_min, out_max):
    mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
    if out_min <= out_max:
        return max(min(mapped, out_max), out_min)
    return min(max(mapped, out_max), out_min)


servo_angles = [90] * 4

while True:
    readings = []
    angles = []
    for i in range(len(pots)):
        # Read 5 potentiometers
        reading = seesaw.analog_read(pots[i])
        readings.append(reading)
        # Map 10-bit value to servo angle
        if i == 5:
            # The 5th servo is for the claw and it doesnt need full range
            angle = int(map_range(reading, 0, 1023, 0, 50))
        else:
            # Other 4 servos are for motion, map to 180 degrees!
            angle = int(map_range(reading, 0, 1023, 0, 180))
        angles.append(angle)
        # set the angle
        servos[i].angle = angle
    # For our debugging!
    print(readings, angles)