NiklasRosenstein / myo-python

Python bindings for the Myo SDK
Other
259 stars 102 forks source link

Making Myo Armband vibrate #54

Closed Mel-Srt closed 6 years ago

Mel-Srt commented 6 years ago

Hi, I would like to know how to make the myo armband vibrate (sorry, I'm not an expert of Python). Here is my code:

import time
import myo as libmyo
libmyo.init('D:/Program Files/myo-sdk-win-0.9.0/bin')

class Listener(libmyo.DeviceListener):

    def on_connect(self, myo, timestamp, firmware_version):
        print("Hello, Myo!")

    def on_disconnect(self, myo, timestamp):
        print("Goodbye, Myo!")

    def on_battery_level(self, event):
        print("Your battery level is:", event.battery_level)

    def on_pose(self, myo, timestamp, pose):
        if pose == libmyo.Pose.fist:
            print("Pose: Fist")
            return False
        if pose == libmyo.Pose.double_tap:
            print("Pose: Double tap")
            return False

hub = libmyo.Hub()
listener = Listener()
hub.run(1000, listener)
try:
    while hub.running:
        print("listening")
        time.sleep(0.5)
except KeyboardInterrupt:
    print("Quitting...")
finally:
    hub.shutdown()

If I want to make the armband vibrate just after the fist pose detected, what should I add? I saw that there is the function vibrate() in the class MyoProxy, and I tried some things, but I didn't succeed. Thank you in advance

NiklasRosenstein commented 6 years ago

Hi @Mel-Srt ,

there's some code in the examples:

https://github.com/NiklasRosenstein/myo-python/blob/1a07093ff1d7d485f9ef8f47aad07586da22f4fb/examples/hello_myo.py#L66-L68

Does this help you?