def vibrate(level, drv):
    # control vibration level at 20 60 and 100
    if level <= 100 and level > 60:
        drv.sequence[0] = adafruit_drv2605.Effect(47)
    elif level >= 60:
        drv.sequence[0] = adafruit_drv2605.Effect(49)
    else:
        drv.sequence[0] = adafruit_drv2605.Effect(51)

    drv.play()
    def run(self):
        while self._running:
            if not q.empty():
                item = q.get()
                print(item)
                #l = item['belt']
                b = item['buzz']
                if item['start'] == 1:
                    if (b < 8):
                        self.drv[b].sequence[0] = adafruit_drv2605.Effect(
                            item['pattern'])  #adafruit-DRV
                        #self.drv[b].sequence[1] = adafruit_drv2605.Pause(item['duration']) #adafruit-DRV                        self.drv[b].sequence[1] = adafruit_drv2605.Effect(47) #adafruit-DRV

                        #self.drv[b].sequence[1] = adafruit_drv2605.Effect(118) #adafruit-DRV
                        #self.drv[b].sequence[3] = adafruit_drv2605.Pause(item['duration']) #adafruit-DRV

                        #self.drv[b].sequence[2] = adafruit_drv2605.Effect(118) #adafruit-DRV
                        #self.drv[b].sequence[5] = adafruit_drv2605.Pause(item['duration']) #adafruit-DRV

                        #self.drv[b].sequence[6] = adafruit_drv2605.Effect(51) #adafruit-DRV
                        self.drv[b].sequence[1] = adafruit_drv2605.Pause(
                            item['duration'])  #adafruit-DRV
                        self.drv[b].play()  #adafruit-DRV
                        check = 'server'
                        self.drv[b].check(check)
                        self.drv[b].log(check)
                        # time.sleep(0.2) # item['duration']) # variable to adjust timing if required
                        t = threading.Timer(item['duration'], stop_buzzer, [b],
                                            {})
                        #t = threading.Timer(item['duration'], stop_buzzer, [l], [b], {})
                        t.start()
                else:
                    if (b < 8):
                        self.drv[b].stop()  #adafruit-DRV
        return
Beispiel #3
0
def drv_effect_run(effect_id=1):
    #play selected effect
    effect_id = drv_set_effect(effect_id)
    drv.sequence[0] = adafruit_drv2605.Effect(effect_id)
    drv.play()
    time.sleep(0.5)
    drv.stop()
Beispiel #4
0
def vibrate(num, duration, delay):
    # 16 is the vibration effect being used for the haptic motor
    drv.sequence[0] = adafruit_drv2605.Effect(16)
    for _ in range(0, num):
        drv.play()  # start vibration
        time.sleep(duration)
        drv.stop()  # stop vibration
        time.sleep(delay)
Beispiel #5
0
def playHeartBeat(heartRate):

    # Initialize I2C bus and DRV2605 module.
    i2c = busio.I2C(board.SCL, board.SDA)
    drv = adafruit_drv2605.DRV2605(i2c)

    # Main loop runs forever trying each effect (1-123).
    # See table 11.2 in the datasheet for a list of all the effect names and IDs.
    #   http://www.ti.com/lit/ds/symlink/drv2605.pdf
    softPulse = 21
    hardPulse = 17
    beatLength = 0.5
    #     heartRate = 68
    if heartRate > 0 and heartRate < 120:
        heartRate = 68

    pauseLength = (60 / heartRate) - beatLength

    if pauseLength < 0:
        pauseLength = 0.1

    counter = 0
    while True:

        #             print('Playing effect #{0}'.format("softPulse: " + str(softPulse)))
        drv.sequence[0] = adafruit_drv2605.Effect(
            softPulse)  # Set the effect on slot 0.

        #             print('Playing effect #{0}'.format("hardPulse: " + str(hardPulse)))
        drv.sequence[1] = adafruit_drv2605.Effect(
            hardPulse)  # Set the effect on slot 0.

        # You can assign effects to up to 7 different slots to combine
        # them in interesting ways. Index the sequence property with a
        # slot number 0 to 6.
        # Optionally, you can assign a pause to a slot. E.g.
        # drv.sequence[1] = adafruit_drv2605.Pause(0.5)  # Pause for half a second
        drv.play()  # play the effect
        time.sleep(beatLength)  # for 0.5 seconds
        drv.stop()  # and then stop (if it's still running)
        time.sleep(pauseLength)
Beispiel #6
0
def adafruit():
    import board
    import busio
    import adafruit_drv2605

    i2c = busio.I2C(board.SCL, board.SDA)
    drv = adafruit_drv2605.DRV2605(i2c)
    for i in range(123):
        drv.sequence[i] = adafruit_drv2605.Effect(i)
        drv.play()
        time.sleep(0.5)
        drv.stop()
Beispiel #7
0
def drv_run():
    effect_id = 1
    print('DRV2605 haptic effect: #{0}'.format(effect_id))
    # Set the effect on slot 0.
    drv.sequence[0] = adafruit_drv2605.Effect(effect_id)
    # (assign effects to up to 7 different slots to combine)
    # drv.sequence[1] = adafruit_drv2605.Pause(0.5)  # Pause for half a second
    drv.play()
    time.sleep(0.5)
    drv.stop()
    # Increment effect ID and wrap back to 1.
    effect_id += 1
    if effect_id > 123:
        effect_id = 1
Beispiel #8
0
	def action(self, action_info):
		if 'action' not in action_info:
			action_info['action'] = self._effect
		super().action(action_info)
		action = action_info['action']
		
		# Set variables
		effect = self._effect
		if 'effect' in action_info:
			if type(action_info['effect']) is not str and type(action_info['effect']) is not int and type(action_info['effect']) is not float:
				raise TypeError("effect in output {} must be type int".format(self.name))
			effect = int(action_info['effect'])
			if effect < 1 or effect > 123:
				raise ValueError("Invalid effect value for {}".format(self.name))
			self._effect = effect
		if not effect:
			raise KeyError("effect is required for {} action {}".format(self.type, self.name))
		
		self._connection.sequence[0] = adafruit_drv2605.Effect(effect)
		self._connection.play()
Beispiel #9
0
    def run(self):
        while self._running:
            if not q.empty():
                item = q.get()
                print(item)
                i = item['buzz']
                if item['start'] == 1:
                    if (i < 8):
                        self.drv[i].sequence[0] = adafruit_drv2605.Effect(
                            item['pattern'])
                        self.drv[i].sequence[1] = adafruit_drv2605.Pause(
                            item['duration'])
                        self.drv[i].play()
                        t = threading.Timer(item['duration'], stop_buzzer, [i],
                                            {})
                        t.start()
                else:
                    if (i < 8):
                        self.drv[i].stop()

        return
Beispiel #10
0
import board
import busio

import adafruit_drv2605

# Initialize I2C bus and DRV2605 module.
i2c = busio.I2C(board.SCL, board.SDA)
drv = adafruit_drv2605.DRV2605(i2c)

# Main loop runs forever trying each effect (1-123).
# See table 11.2 in the datasheet for a list of all the effect names and IDs.
#   http://www.ti.com/lit/ds/symlink/drv2605.pdf
effect_id = 1
while True:
    print("Playing effect #{0}".format(effect_id))
    drv.sequence[0] = adafruit_drv2605.Effect(
        effect_id)  # Set the effect on slot 0.
    # You can assign effects to up to 7 different slots to combine
    # them in interesting ways. Index the sequence property with a
    # slot number 0 to 6.
    # Optionally, you can assign a pause to a slot. E.g.
    # drv.sequence[1] = adafruit_drv2605.Pause(0.5)  # Pause for half a second
    drv.play()  # play the effect
    time.sleep(0.5)  # for 0.5 seconds
    drv.stop()  # and then stop (if it's still running)
    # Increment effect ID and wrap back around to 1.
    effect_id += 1
    if effect_id > 123:
        effect_id = 1
Beispiel #11
0
def vibe(num_zzz, effect, delay):
    drv.sequence[0] = adafruit_drv2605.Effect(effect)
    for _ in range(0, num_zzz):
        drv.play()  # play the effect
        time.sleep(delay)  # for 0.5 seconds
        drv.stop()
Beispiel #12
0
 def play_effect (self):
     # define effect ID from 1 to 123
     effect_id = 17
     self._drv.sequence[0] = adafruit_drv2605.Effect(effect_id)
     self._drv.play()  # play the effect
    return not button_a.value


def touch_b():
    return not button_b.value


while True:
    if touch_a():
        print("\nRight Bumper\n")

        # Set NeoPixel colour to green on button press
        cp.pixels[0] = (0, 255, 0)

        # Play haptic waveform sequence
        drv.sequence[0] = adafruit_drv2605.Effect(64)
        drv.sequence[1] = adafruit_drv2605.Effect(58)
        drv.play()

        while touch_a():
            pass
    else:
        cp.pixels[0] = (0, 0, 0)

    if touch_b():
        print("\nLeft Bumper\n")

        # Set NeoPixel colour to green on button press
        cp.pixels[9] = (0, 255, 0)

        # Play haptic waveform sequence
GPIO.setup(input_port, GPIO.IN,
           pull_up_down=GPIO.PUD_UP)  # set GPIO12 as input (button)
# GPIO.setup(output_port, GPIO.OUT)   # set GPIO13 as an output (LED)

#initialize the haptics

import board
import busio
import adafruit_drv2605

haptics = True

try:
    i2c = busio.I2C(board.SCL, board.SDA)
    drv = adafruit_drv2605.DRV2605(i2c)
    drv.sequence[0] = adafruit_drv2605.Effect(47)
except ValueError as e:
    haptics = False

#create thread
thread = Thread()
thread_stop_event = Event()


class RandomThread(Thread):
    def __init__(self):
        self.delay = 0.05
        super(RandomThread, self).__init__()

    def countButtonPush(self):
        lastButtonState = 0
    while not ble.connected:
        pass

    # Now we're connected

    while ble.connected:
        if uart.in_waiting:
            packet = Packet.from_stream(uart)
            if isinstance(packet, ButtonPacket):
                if packet.pressed:
                    if packet.button == ButtonPacket.BUTTON_1:
                        # The 1 button was pressed.
                        print(
                            "\nPULSES\nPulsing Strong 1\nPulsing Strong 2\nPulsing Medium 1\nPulsing Medium 2"
                        )
                        drv.sequence[0] = adafruit_drv2605.Effect(52)
                        drv.sequence[1] = adafruit_drv2605.Pause(1)
                        drv.sequence[2] = adafruit_drv2605.Effect(53)
                        drv.sequence[3] = adafruit_drv2605.Pause(1)
                        drv.sequence[4] = adafruit_drv2605.Effect(54)
                        drv.sequence[5] = adafruit_drv2605.Pause(1)
                        drv.sequence[6] = adafruit_drv2605.Effect(55)
                        drv.play()
                        #-----
                        time.sleep(6)
                        drv.stop()
                    elif packet.button == ButtonPacket.BUTTON_2:
                        # The 2 button was pressed.
                        print(
                            "\nPULSES *TEST*\nPulsing Strong 2\nPulsing Medium 2\nPulsing Medium 1\nPulsing Strong 1"
                        )