Min Ma
Created August 19, 2024

Virtual Gamepad with Vision AI

Using Vision AI model Build Virtual Gamepad Communicate with BlueTooth.

13
Virtual Gamepad with Vision AI

Things used in this project

Hardware components

Seeed Studio Vision AI Module 2
×1
Seeed Studio OV5647-62 FOV Camera Module
×1
Espressif Esp32 module
×1

Story

Read more

Code

Virtual Gamepad with Vision AI

Arduino
Virtual Gamepad with Vision AI
#include <Arduino.h>
#include <Seeed_Arduino_SSCMA.h>
#include <BleGamepad.h>

BleGamepad bleGamepad;
SSCMA AI;

int CenterX = 110;
int CenterY = 100;
int theta   = 10;
bool first  = true;

void setup()
{
    Serial.begin(9600);
    Serial.println("Starting BLE gamepad App!");

    //initial and setup Grove Vision 2
    AI.begin();

    //initial gamepad
    bleGamepad.begin();   
}

void loop()
{
    // invoke once, no filter , get image
    if (!AI.invoke(1, false, true))
    {
        //first time, caliberate the center point
        if(first && AI.boxes().size()>1)
        {
            CenterX = AI.boxes()[0].x;
            CenterY = AI.boxes()[0].x;
            first = false;
        }

        //filter multiface detect, only select first.
        if (AI.boxes().size()>1)
        {
            if(AI.boxes()[0].x < CenterX - theta)
            {
                bleGamepad.setHat1(DPAD_LEFT);
            }

            if( AI.boxes()[0].x > CenterX + theta)
            {
                bleGamepad.setHat1(DPAD_RIGHT);
            }

            if( AI.boxes()[0].y > CenterY + theta)
            {
                bleGamepad.setHat1(DPAD_DOWN);
            }

            if( AI.boxes()[0].y < CenterY - theta)
            {
                bleGamepad.setHat1(DPAD_UP);
            }
        }
    }

    //interval 0.5 seconds.
    delay(500);

}

Credits

Min Ma

Min Ma

8 projects • 1 follower
Senior Software Engineer

Comments