示例#1
0
    def touched(self):
        anyButtonTouched = self.i2c.write_read(self.addr, CAP_TOUCH_GENERAL_STATUS, 1)[0]
        #print(anyButtonTouched)
        response = '0'
        if anyButtonTouched == 33:
            #print(anyButtonTouched)
            button = self.i2c.write_read(self.addr, CAP_TOUCH_SENSOR_INPUT_STATUS, 1)[0]
            if button == 0x01:
                #print(button)
                response = 'triangle'
            if button == 0x20:
                #print(button)
                response = 'circle'
            if button == 0x08:
                #print(button)
                response = 'cross'
            if button == 0x10:
                #print(button)
                response = 'square'
            xCore.sleep(100)
            self.i2c.write_bytes(self.addr, 0x00, 0x00)
        else:
            pass
            #print('no touch detected')

        return response
示例#2
0
    def begin(self):

        ID = self.i2c.write_read(self.addr, CSS811_REG_HW_ID, 1)[0]

        if ID == CSS811_HW_CODE:
            self.sw_reset()
            xCore.sleep(10)
            self.i2c.send_byte(self.addr, CCS811_BOOTLOADER_APP_START)
            xCore.sleep(10)

            if self.checkForStatusError() == True:
                return False

            self.disableInterrupt()
            self.setDriveMode(CCS811_DRIVE_MODE_1SEC)
            return True
        else:
            False
示例#3
0
from xOC05 import xOC05
from xCore import xCore

# OC05 instance
OC05 = xOC05()

# configure OC05 with frequency of 60Hz
OC05.init(60)

while True:
    OC05.setServoPosition(1, 0)  #  position servo to the right
    xCore.sleep(50)
    OC05.setServoPosition(1, 180)  #  position servo to the left
    xCore.sleep(50)
示例#4
0
from xCore import xCore
from xSL06 import xSL06

# SL06 instance
SL06 = xSL06()

# configure SL06
SL06.init()

# enable SL06 for light sensing
SL06.enableLightSensor()

while True:
    light = SL06.getAmbientLight()  # read the the ambient light level
    print('Ambient Light Level: ', light)

    xCore.sleep(2000)
示例#5
0
from xCore import xCore
from xOD01 import xOD01

OD01 = xOD01()

OD01.clear()

while True:

    OD01.text("Hello World", 0, 0)
    # scroll right
    OD01.hw_scroll_h()
    xCore.sleep(3000)
    # scroll left
    OD01.hw_scroll_h(False)
    xCore.sleep(3000)
    OD01.hw_scroll_off()
    xCore.sleep(3000)
    OD01.clear()
    xCore.sleep(1000)
示例#6
0
    def getGesture(self):
        fifo_level = 0
        fifo_data = []

        mode = self.getMode() & 0b01000001
        if not self.isGestureAvailable() or not mode:
            return DIR_NONE

        while True:

            xCore.sleep(FIFO_PAUSE_TIME)

            try:
                gstatus = self.i2c.write_read(self.addr, APDS9960_GSTATUS,
                                              1)[0]
            except Exception as e:
                #raise e
                pass

            if (gstatus & APDS9960_GVALID) == APDS9960_GVALID:

                try:
                    fifo_level = self.i2c.write_read(self.addr, APDS9960_GFLVL,
                                                     1)[0]
                except Exception as e:
                    #raise e
                    pass

                if fifo_level > 0:

                    try:
                        fifo_data = self.i2c.write_read(
                            self.addr, APDS9960_GFIFO_U, fifo_level * 4)
                    except Exception as e:
                        #raise e
                        pass
                    if len(fifo_data) >= 4:
                        for i in range(0, len(fifo_data), 4):
                            self.gesture_data_.u_data[
                                self.gesture_data_.index] = fifo_data[i + 0]
                            self.gesture_data_.d_data[
                                self.gesture_data_.index] = fifo_data[i + 1]
                            self.gesture_data_.l_data[
                                self.gesture_data_.index] = fifo_data[i + 2]
                            self.gesture_data_.r_data[
                                self.gesture_data_.index] = fifo_data[i + 3]
                            self.gesture_data_.index += 1
                            self.gesture_data_.total_gestures += 1

                        if self.processGestureData():
                            if self.decodeGesture():
                                pass

                        self.gesture_data_.index = 0
                        self.gesture_data_.total_gestures = 0
            else:

                xCore.sleep(FIFO_PAUSE_TIME)
                if not self.decodeGesture():
                    pass

                motion = self.gesture_motion_

                self.resetGestureParameters()
                return motion
示例#7
0
from xOC03 import xOC03
from xCore import xCore

OC03 = xOC03()

# start OC03
OC03.init()

# sleep time
DELAY = 500

# infinite loop
while True:

    # close relay
    OC03.writePin(True)
    xCore.sleep(DELAY)

    # open relay
    OC03.writePin(False)
    xCore.sleep(DELAY)