There was a lot of cool stuff made during #thalmichackd last weekend. We'll probably come back to some of the other hacks later, but for this week's #MyoCraft I want to talk about my personal favourite, the 10ft Media Experience, by our own Chris Goodine (@chris_goodine).

Download version of the script this post is based on here, in case the Myo Market version gets updated.

The idea with this one is that you have a single script that controls multiple different applications with your Myo armband, with a special escape gesture always available to enable mouse control. The big advantage is you won't get stuck. You can navigate around your computer using mouse control, and control music running in the background using the media keys. If you open up Netflix, you can take control with the Netflix specific control scheme. Raise your arm and double tap, and you have mouse control back again and can go to another application.

Media

Right now this is completely media specific, but you could imagine adding additional controls for other applications as well. Maybe combine it with a script to control your browser, make music, or to paint. The sky's the limit!

Now, this script is over 600 lines long, and it does a few interesting things that we'll probably come back to in the future. This week though I want to focus on how the mouse control is activated.

First, onPeriodic:

  
 



function onPeriodic()  
        local now = myo.getTimeMilliseconds()
        local pitch = myo.getPitch()
        local xDirection = myo.getXDirection()

        if pitch > PITCH_THRESHOLD and xDirection ~= "unknown" then
            toggleZone = true
            if (now - sinceBeat) > HEARTBEAT_PERIOD then
                heartbeat()
                sinceBeat = now
            end
        else
            toggleZone = false
        end

        --etc 

The script is always waiting for you to raise your arm up 90 degrees. When you are in that zone, you get a subtle heartbeat vibration. That's your signal to either double tap and activate mouse control, or move your arm to get out of the zone.

heartbeat() just calls notifyUserAction(), incidentally.

We are also careful to check myo.getXDirection(). That will return unknown when the Myo armband isn't synced, so you don't get the heartbeat if your Myo armband is just sitting on the desk.

Anyway, since we are using the standard locking policy, when the Myo armband is locked, any time they double tap it unlocks for them. onUnlock() also gets called, and we take the opportunity to enable mouse control if we're in the right zone.

  
 



function onUnlock()  
        -- Enable mouse control if arm is within toggleZone
        if myo.mouseControlEnabled() == false and toggleZone then
            enableMouseControl()
        end
    end

Finally, once we're actually in mouse control mode, onPoseEdge will need to handle it:

  
  



function onPoseEdge(pose, edge)  
        local now = myo.getTimeMilliseconds()

        -- Disable mouse control
        if pose == "doubleTap" and edge == "on" then
            if myo.mouseControlEnabled() then
                disableMouseControl()
            end
        end

        if myo.mouseControlEnabled() then
            -- Mouse Controls
            if edge == "on" then
                if pose == "fist" then
                    myo.mouse("left", "down")
                elseif pose == "waveOut" then
                    myo.mouse("right", "click")
                elseif pose == "waveIn" then
                    myo.mouse("left", "click")
                    myo.mouse("left", "click")
                end
            elseif edge == "off" and pose == "fist" then
                myo.mouse("left", "up")
            end
        else

        -- Media controls

This concept of special actions only being available while you arm is at your side or up in the air is a powerful one. Because it can be corrected using gravity, pitch is always a pretty reliable measurement, removing the need for any kind of "centreing" gesture. It's a good way to expand your control surface, or to keep certain actions from being triggered unless they are REALLY intentional.

That's it for now! Don't forget to send us your #MyoCraft ideas!

Otherwise, see you next week!

Newsletter

Enter your email address and get all latest content delivered to your inbox every now and then.