Robotica DIY
Published © MIT

How to Make Gesture Control Game with Arduino Leonardo

You are playing video game with your own gesture control via Arduino Leonardo or you can say we are controlling computer with hand gestures

IntermediateFull instructions provided1 hour1,168
How to Make Gesture Control Game with Arduino Leonardo

Story

Read more

Code

calibrating sensor

Plain text
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}

Arduino Game Controller Code

Plain text
//RoboticaDIY.com

#include "Keyboard.h"

void setup() {
Serial.begin (9600);

// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {

int accelerator = analogRead(A0); //Flex Sensor 1
int brake = analogRead(A1); //Flex Sensor 2
int x = analogRead(A4); // ADXL335 x
int y = analogRead(A5); // ADXL335 y

if (accelerator > 450 ){
Keyboard.write('W');
delay(10);
}
if (brake > 400 ){
Keyboard.write('S');
delay(10);
}
if (x <330){ //RIGHT
Keyboard.press('R');
delay(250);
Keyboard.releaseAll();
}
if (y <380){ //LEFT
Keyboard.press('L');
delay(250);
Keyboard.releaseAll();
} 
}

Code snippet #8

Plain text
if (x <330){
Keyboard.press('R');
delay(250);
Keyboard.releaseAll();
}
if (y <380){
Keyboard.press('L');
delay(250);
Keyboard.releaseAll();
}

Credits

Robotica DIY

Robotica DIY

16 projects • 18 followers
Robotica DIY is for those who want to learn themselves. You will get projects on Arduino, Raspberry pi & NodeMcu ESP8266.

Comments