Amr Salehyejun
Published

GamePad using Android mobile sensors and Arduino

Play video games on your laptop using your phone as a gamepad

Full instructions provided8,525
GamePad using Android mobile sensors and Arduino

Things used in this project

Story

Read more

Code

Untitled file

Arduino
#include <OneSheeld.h>

void setup() 
{
  OneSheeld.begin();
  Serial.begin(9600);
  Keyboard.begin();
}

void loop() 
{
  if (GamePad.isUpPressed())
  {Keyboard.press(0xDA);}
  else
  {Keyboard.release(0xDA);}
  
 if(GamePad.isDownPressed())
  {Keyboard.press(0xD9);}
  else
  {Keyboard.release(0xD9);}

 if (GravitySensor.getY() < -1)
  {Keyboard.press(0xD8);}
  else{Keyboard.release(0xD8);}
  
 if (GravitySensor.getY() > 1)
  {Keyboard.press(0xD7);}
  else
  {Keyboard.release(0xD7);}
  
  if (GamePad.isGreenPressed())
  {Keyboard.press(0x80);}
  else
  {Keyboard.release(0x80);}
  //delay(30);
  
}

Codebender

https://codebender.cc/sketch:53866

Credits

Ashraf Nabil

Posted by Amr Saleh

Comments