WeeNS

WeeNS is a controller that tracks your movement and makes the game follow the directions you are giving to him. In this case we are doing it with a Frogger we made in Processing.

Step 1: Materials

- (x1) Arduino Nano

- (x1) Accelerometer

- (x1) Led

- (x1) Resistance

- Jumper wires

Step 2: Arduino to Processing

So that the result of our movement is shown on the screen or the game first we need to connect arduino with procesing and we will print the movement that we make with the function of println () as shown below:

#include
#include MMA8452Q accel;

const int ledPin = 5;

void setup(){

Serial.begin(9600);

Serial.println("MMA8452Q Test Code!");

accel.init();

pinMode(ledPin, OUTPUT);

}

void loop(){

digitalWrite(ledPin, HIGH);

if (accel.available()){

accel.read();

printOrientation();

Serial.println();

}

}

void printOrientation(){

byte pl = accel.readPL();

switch (pl){

case PORTRAIT_U:

Serial.print("s");

delay(250);

break;

case PORTRAIT_D:

Serial.print("w");

delay(250);

break;

case LANDSCAPE_R:

Serial.print("a");

delay(250);

break;

case LANDSCAPE_L:

Serial.print("d");

delay(250);

break;

case LOCKOUT:

Serial.print("Flat");

delay(250);

break;

}

}

Step 3: Controlls

In order to move the pj in the game what we will do is tell it to interpret the println () that we are sending from arduino to processing as if we were pressing the keys of the game.

You can do this with every game you want, but remember that the accelerometer needs to be calibrated in order to have the correct information sended, if you want to go forward we recommend you to first look in which direction you places your accelerometer.

void draw()
{

//Arduino Link

if ( myPort.available() > 0){

println(val);

val = myPort.readStringUntil('\n');

if (val!=null) {

if (val.substring(0,1).equals("w")){

Frogger.Y -= 80; //print it out in the console

}

else if (val.substring(0,1).equals("s")){

Frogger.Y += 80; //print it out in the console

}

else if (val.substring(0,1).equals("a")){

Frogger.X -= 80; //print it out in the console

}

else if (val.substring(0,1).equals("d")){

Frogger.X += 80; //print it out in the console

}

Step 4: Controller

We recommend that you use a box that you have at home or anything you can use to move the command of the game with ease, in our case we printed the case of a console controller similar to the command of NES.

Step 5: Enjoy !

Share

    Recommendations

    • Comfort Food Challenge

      Comfort Food Challenge
    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • Safe and Secure Challenge

      Safe and Secure Challenge

    Discussions