# Simple seesaw test using an LED attached to Pin 15.
#
# See the seesaw Learn Guide for wiring details:
# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test
import time

from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw

i2c_bus = busio.I2C(SCL, SDA)

ss = Seesaw(i2c_bus)

ss.pin_mode(15, ss.OUTPUT)

while True:
    ss.digital_write(15, True)  # turn the LED on (True is the voltage level)
    time.sleep(1)  # wait for a second
    ss.digital_write(15, False)  # turn the LED off by making the voltage LOW
    time.sleep(1)
Exemplo n.º 2
0
class DummyAudio:
    def play(self, f, loop=False):
        pass

    def stop(self):
        pass

    def mute(self, mute):
        pass


i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
spi = board.SPI()
displayio.release_displays()
while not spi.try_lock():
    pass
spi.configure(baudrate=24000000)
spi.unlock()
ss.pin_mode(8, ss.OUTPUT)
ss.digital_write(8, True) # reset display
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80,
                            rowstart=24)
del _INIT_SEQUENCE
buttons = GamePadSeesaw(ss)
audio = DummyAudio()
backlight = PWMOut(ss, 5)
backlight.duty_cycle = 0
Exemplo n.º 3
0
LOOKRIGHT = 120

#################### 1 Servo
pwm = PWMOut(ss, 17)
pwm.frequency = 50
myservo = servo.Servo(pwm)
myservo.angle = LOOKATPERSON  # introduce yourself

#################### 2 buttons w/2 LEDs
BUTTON_1 = 2
BUTTON_2 = 3
LED_1 = 8
LED_2 = 9

# Two buttons are pullups, connect to ground to activate
ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP)
ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP)
# Two LEDs are outputs, on by default
ss.pin_mode(LED_1, ss.OUTPUT)
ss.pin_mode(LED_2, ss.OUTPUT)
ss.digital_write(LED_1, True)
ss.digital_write(LED_2, True)

#################### log files
logfile = "/log.csv"
# check that we could append if wanted to
try:
    fp = open(logfile, "a")
    fp.close
except:
    print("File system not writable, halting")
Exemplo n.º 4
0
"""

import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_seesaw.seesaw import Seesaw
from adafruit_st7735r import ST7735R

# Release any resources currently in use for the displays
displayio.release_displays()

reset_pin = 8
i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
ss.pin_mode(reset_pin, ss.OUTPUT)

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)

ss.digital_write(reset_pin, True)
display = ST7735R(display_bus,
                  width=160,
                  height=80,
                  colstart=24,
                  rotation=270,
                  bgr=True)
Exemplo n.º 5
0
class MiniTFTFeatherWing:
    """Class representing an `Mini Color TFT with Joystick FeatherWing
       <https://www.adafruit.com/product/3321>`_.

       Automatically uses the feather's I2C bus."""

    _button_mask = ((1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
                    (1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_SEL) |
                    (1 << BUTTON_A) | (1 << BUTTON_B))

    #pylint: disable-msg=too-many-arguments
    def __init__(self, address=0x5E, i2c=None, spi=None, cs=None, dc=None):
        displayio.release_displays()
        if i2c is None:
            i2c = board.I2C()
        if spi is None:
            spi = board.SPI()
        if cs is None:
            cs = board.D5
        if dc is None:
            dc = board.D6
        self._ss = Seesaw(i2c, address)
        self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
        self._ss.pin_mode(8, self._ss.OUTPUT)
        self._ss.digital_write(8, True)  # Reset the Display via Seesaw
        self._backlight = PWMOut(self._ss, 5)
        self._backlight.duty_cycle = 0
        display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
        self.display = ST7735R(display_bus,
                               width=160,
                               height=80,
                               colstart=24,
                               rotation=270,
                               bgr=True)

    #pylint: enable-msg=too-many-arguments

    @property
    def backlight(self):
        """
        Return the current backlight duty cycle value
        """
        return self._backlight.duty_cycle / 255

    @backlight.setter
    def backlight(self, brightness):
        """
        Set the backlight duty cycle
        """
        self._backlight.duty_cycle = int(255 * min(max(brightness, 0.0), 1.0))

    @property
    def buttons(self):
        """
        Return a set of buttons with current push values
        """
        try:
            button_values = self._ss.digital_read_bulk(self._button_mask)
        except OSError:
            return Buttons(*[
                False
                for button in (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT,
                               BUTTON_RIGHT, BUTTON_A, BUTTON_B, BUTTON_SEL)
            ])
        return Buttons(*[
            not button_values & (1 << button)
            for button in (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT,
                           BUTTON_A, BUTTON_B, BUTTON_SEL)
        ])
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
Exemplo n.º 7
0
seesaw = Seesaw(i2c)

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN

buttonb = DigitalInOut(board.BUTTON_B)
buttonb.direction = Direction.INPUT
buttonb.pull = Pull.DOWN

BOTTOM_SENSOR = 2
TOP_SENSOR = 3
seesaw.pin_mode(BOTTOM_SENSOR, seesaw.INPUT_PULLUP)
seesaw.pin_mode(TOP_SENSOR, seesaw.INPUT_PULLUP)

# Create one stepper motor using the 4 'drive' PWM pins 13, 43, 12 and 42
pwms = [PWMOut(seesaw, 13), PWMOut(seesaw, 43), PWMOut(seesaw, 12), PWMOut(seesaw, 42)]
for p in pwms:
    p.frequency = 2000
stepper_motor = stepper.StepperMotor(pwms[0], pwms[1], pwms[2], pwms[3])

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)
pixels.fill((0,0,0))


def rainbow():
    pixels.fill((20,0,0))
    time.sleep(0.05)
Exemplo n.º 8
0
led.direction = Direction.OUTPUT

# Two onboard CPX buttons for FOG
buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN

buttonb = DigitalInOut(board.BUTTON_B)
buttonb.direction = Direction.INPUT
buttonb.pull = Pull.DOWN

# Use the signal port for potentiometer w/switch
MORECOW = 2  # A switch on Signal #1
SWITCH = 3  # A potentiometer on Signal #2
# Add a pullup on the switch
seesaw.pin_mode(SWITCH, seesaw.INPUT_PULLUP)

# Servo angles
BELL_START = 60
BELL_END = 75
MOUTH_START = 95
MOUTH_END = 105

# Create servos list
servos = []
for ss_pin in (17, 16):  #17 is labeled 1 on CRICKIT, 16 is labeled 2
    pwm = PWMOut(seesaw, ss_pin)
    pwm.frequency = 50  #must be 50 cannot change
    _servo = servo.Servo(pwm, min_pulse=400, max_pulse=2500)
    servos.append(_servo)
# Starting servo locations
class MiniTFTFeatherWing:
    """Class representing an `Mini Color TFT with Joystick FeatherWing
       <https://www.adafruit.com/product/3321>`_.

       Automatically uses the feather's I2C bus."""

    _button_mask = ((1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
                    (1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_SEL) |
                    (1 << BUTTON_A) | (1 << BUTTON_B))

    def __init__(self, address=0x5E, i2c=None, spi=None):
        if i2c is None:
            i2c = board.I2C()
        if spi is None:
            spi = board.SPI()
        self._ss = Seesaw(i2c, address)
        self._backlight = PWMOut(self._ss, 5)
        self._backlight.duty_cycle = 0
        displayio.release_displays()
        while not spi.try_lock():
            pass
        spi.configure(baudrate=24000000)
        spi.unlock()
        self._ss.pin_mode(8, self._ss.OUTPUT)
        self._ss.digital_write(8, True)  # Reset the Display via Seesaw
        display_bus = displayio.FourWire(spi,
                                         command=board.D6,
                                         chip_select=board.D5)
        self.display = ST7735R(display_bus,
                               width=160,
                               height=80,
                               colstart=24,
                               rotation=270,
                               bgr=True)
        self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)

    @property
    def backlight(self):
        """
        Return the current backlight duty cycle value
        """
        return self._backlight.duty_cycle / 255

    @backlight.setter
    def backlight(self, brightness):
        """
        Set the backlight duty cycle
        """
        self._backlight.duty_cycle = int(255 *
                                         min(max(1 - brightness, 0.0), 1.0))

    @property
    def buttons(self):
        """
        Return a set of buttons with current push values
        """
        button_values = self._ss.digital_read_bulk(self._button_mask)
        return Buttons(*[
            not button_values & (1 << button)
            for button in (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT,
                           BUTTON_A, BUTTON_B, BUTTON_SEL)
        ])
Exemplo n.º 10
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
Exemplo n.º 11
0
class MiniTFTFeatherWing_T:
    """
    Row display for MiniTFT Featherwing
    """
    def __init__(self):
        self.reset_pin = 8
        self.i2c = board.I2C()
        self.ss = Seesaw(self.i2c, 0x5E)
        self.ss.pin_mode(self.reset_pin, self.ss.OUTPUT)

        self.spi = board.SPI()
        self.tft_cs = board.D5
        self.tft_dc = board.D6
        self._auto_show = True

        displayio.release_displays()
        self.display_bus = displayio.FourWire(self.spi,
                                              command=self.tft_dc,
                                              chip_select=self.tft_cs)

        self.ss.digital_write(self.reset_pin, True)
        self.display = ST7735R(self.display_bus,
                               width=160,
                               height=80,
                               colstart=24,
                               rotation=270,
                               bgr=True)

        self.nbr_rows = 5
        self.row_height = int(self.display.height / self.nbr_rows)
        self.row_vpos = [
            int(i * self.row_height) for i in range(self.nbr_rows)
        ]
        self.row_bkgnd_color = [
            0x808080, 0xFF0000, 0x000040, 0x0000FF, 0xAA0088
        ]
        self.row_text_color = [
            0xFFFFFF, 0xFFFF00, 0xFF0000, 0xFFFF00, 0xFAFAFA
        ]
        self.row_text = ['r1', 'r2', 'r3', 'r4', 'r5']
        # -----------------------------------------------------------------------------------
        # Button handler
        # -----------------------------------------------------------------------------------
        self.btn_mat = []
        self.btn_mat.append([1 << BUTTON_RIGHT, 0, 0, False, 'right'])
        self.btn_mat.append([1 << BUTTON_DOWN, 0, 0, False, 'down'])
        self.btn_mat.append([1 << BUTTON_LEFT, 0, 0, False, 'left'])
        self.btn_mat.append([1 << BUTTON_UP, 0, 0, False, 'up'])
        self.btn_mat.append([1 << BUTTON_SEL, 0, 0, False, 'select'])
        self.btn_mat.append([1 << BUTTON_A, 0, 0, False, 'A'])
        self.btn_mat.append([1 << BUTTON_B, 0, 0, False, 'B'])
        # print(btn_mat)
        self.btn_mask = 0
        for mask_indx in range(len(self.btn_mat)):
            self.btn_mask = self.btn_mask | self.btn_mat[mask_indx][0]
            # print(btn_mask)
        self.ss.pin_mode_bulk(self.btn_mask, self.ss.INPUT_PULLUP)

        self.state_dict = {
            'idle': 0,
            'pressed': 1,
            'pressed_deb': 2,
            'released': 3,
            'released_deb': 4
        }

        self.btn_repeat_time = 1.0
        self.btn_deb_time = 0.1

    def print_at(self, row_indx, txt):
        """
        Print one row a specific row number 0-4

        """
        try:
            self.row_text[row_indx] = txt
        except IndexError:
            self.row_text[self.nbr_rows -
                          1] = 'incorrect row index: ' + str(row_indx)
        if self._auto_show:
            self.show_rows()

    def show_rows(self):
        """
        Show printed rows on the display
        - use print_at to fill the rows first
        - background colors can be changed using the background_color function
        - text colors can be changed using the text_color function
        call show_rows when text and colors are OK
        """
        row_disp = displayio.Group(max_size=10)
        self.display.show(row_disp)
        print('show')
        for i in range(self.nbr_rows):

            # Draw row rectangles
            row_bitmap = displayio.Bitmap(self.display.width, self.row_height,
                                          1)
            row_palette = displayio.Palette(1)
            row_palette[0] = self.row_bkgnd_color[i]
            row_block = displayio.TileGrid(row_bitmap,
                                           pixel_shader=row_palette,
                                           x=0,
                                           y=self.row_vpos[i])
            row_disp.append(row_block)
            text_group = displayio.Group(max_size=10,
                                         scale=1,
                                         x=8 + i,
                                         y=6 + i * self.row_height)
            text_area = label.Label(terminalio.FONT,
                                    text=self.row_text[i],
                                    color=self.row_text_color[i])
            text_group.append(text_area)  # Subgroup for text scaling
            row_disp.append(text_group)

    def background_color(self, row_indx, color_code):
        """
        change background color for one row
        row_indx = 0-4
        color_code = 24 bit binary input 0xrrggbb
        """
        try:
            self.row_bkgnd_color[row_indx] = color_code
        except IndexError:
            self.row_text[self.nbr_rows -
                          1] = 'incorrect row index: ' + str(row_indx)

    def text_color(self, row_indx, color_code):
        """
        change text color for one row
        row_indx = 0-4
        color_code = 24 bit binary input 0xrrggbb
        """
        try:
            self.row_text_color[row_indx] = color_code
        except IndexError:
            self.row_text[self.nbr_rows -
                          1] = 'incorrect row index: ' + str(row_indx)

    @property
    def auto_show(self):
        return self._auto_show

    @auto_show.setter
    def auto_show(self, t_f):
        _auto_show = t_f

    @property
    def backlight(self):
        """
        Return the current backlight duty cycle value
        """
        return self._backlight.duty_cycle / 255

    @backlight.setter
    def backlight(self, brightness):
        """
        Set the backlight duty cycle
        """
        self._backlight.duty_cycle = int(255 * min(max(brightness, 0.0), 1.0))

    # -----------------------------------------------------------------------------------
    def scan(self):
        """
        Class reading the buttons on Mini Color TFT with Joystick FeatherWing
        key pressed-released states implemented
        Keys are repeated if pressed over a time limit
        call btn_scan() as often as possible. no upper limited but slow scanning will
        decrease the performance
        btn_read() returns one key at a time as text. when no key is pressed an
        empty string will be reurned
        * Author Tom Hoglund 2019
        """
        time_now = time.monotonic()
        buttons = self.ss.digital_read_bulk(self.btn_mask)

        for mask_indx in range(len(self.btn_mat)):
            if not buttons & self.btn_mat[mask_indx][0]:
                if self.btn_mat[mask_indx][1] == self.state_dict['idle']:
                    self.btn_mat[mask_indx][1] = self.state_dict['pressed']
                    self.btn_mat[mask_indx][2] = time_now
                elif self.btn_mat[mask_indx][1] == self.state_dict['pressed']:
                    if time_now > self.btn_mat[mask_indx][
                            2] + self.btn_deb_time:
                        self.btn_mat[mask_indx][1] = self.state_dict[
                            'pressed_deb']
                        self.btn_mat[mask_indx][2] = time_now
                elif self.btn_mat[mask_indx][1] == self.state_dict[
                        'pressed_deb']:
                    if time_now > self.btn_mat[mask_indx][
                            2] + self.btn_repeat_time:
                        # btn_mat[mask_indx][1] = state_dict['pressed_deb']
                        self.btn_mat[mask_indx][2] = time_now
                        self.btn_mat[mask_indx][3] = True

            else:
                if self.btn_mat[mask_indx][1] == self.state_dict[
                        'pressed_deb']:
                    self.btn_mat[mask_indx][1] = self.state_dict['released']
                    self.btn_mat[mask_indx][2] = time_now
                elif self.btn_mat[mask_indx][1] == self.state_dict['released']:
                    if time_now > self.btn_mat[mask_indx][
                            2] + self.btn_deb_time:
                        self.btn_mat[mask_indx][1] = self.state_dict[
                            'released_deb']
                        self.btn_mat[mask_indx][3] = True
            if self.btn_mat[mask_indx][1] == self.state_dict['released_deb']:
                if not self.btn_mat[mask_indx][3]:
                    self.btn_mat[mask_indx][1] = self.state_dict['idle']
                    self.btn_mat[mask_indx][2] = time_now

    def read(self):
        ret_val = ''
        for mask_indx in range(len(self.btn_mat)):
            if self.btn_mat[mask_indx][3]:
                self.btn_mat[mask_indx][3] = False
                self.btn_mat[mask_indx][1] = self.state_dict['idle']
                ret_val = self.btn_mat[mask_indx][4]
                break
        return ret_val
Exemplo n.º 12
0
from adafruit_seesaw.seesaw import Seesaw

import terminalio
from adafruit_display_text import label

font = terminalio.FONT

# setup for accelerometer

i2c = busio.I2C(board.SCL, board.SDA)
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x18, int1=int1)

# backlight left display pin initialisation
ss = Seesaw(i2c)
ss.pin_mode(5, ss.OUTPUT)
ss.pin_mode(9, ss.INPUT_PULLUP)
ss.pin_mode(10, ss.INPUT_PULLUP)
ss.pin_mode(11, ss.INPUT_PULLUP)

# display setup for m4sk

displayio.release_displays()

spi1 = busio.SPI(board.RIGHT_TFT_SCK, MOSI=board.RIGHT_TFT_MOSI)
display1_bus = displayio.FourWire(spi1,
                                  command=board.RIGHT_TFT_DC,
                                  chip_select=board.RIGHT_TFT_CS,
                                  reset=board.RIGHT_TFT_RST)
display1 = ST7789(display1_bus,
                  width=240,
Exemplo n.º 13
0
import busio
from adafruit_seesaw.seesaw import Seesaw

i2c_bus = busio.I2C(SCL, SDA)

pwm = pulseio.PWMOut(board.D4, frequency=38000, duty_cycle=2**15)
pulseout = pulseio.PulseOut(pwm)
# Create an encoder that will take numbers and turn them into NEC IR pulses
encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500],
                                            one=[550, 550],
                                            zero=[550, 1700],
                                            trail=0)

ss = Seesaw(i2c_bus)

ss.pin_mode(9, ss.INPUT_PULLUP)

last_x = 0
last_y = 0

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

    if not b:
        encoder.transmit(pulseout, [255, 2, 191, 64])
        time.sleep(.01)
    if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
        #  print(x, y)
        last_x = x