Go Down

Topic: Esplora Accelerometer instead of joystick (Read 54 times) previous topic - next topic


Hello Everyone,

I'm trying to make a game controller so instead of using the joystick you tilt the controller.
It's just a simple X-axis = left right set up but I'm still fairly new and it's giving me grief.

Currently I haven't got the Axis to work at all and the code is churning out 'W' constantly I have no idea why.

#include <Esplora.h>

void setup()

void loop()
 int right = Esplora.readButton(SWITCH_RIGHT);
 int left = Esplora.readButton(SWITCH_LEFT);
 int down = Esplora.readButton(SWITCH_DOWN);
 int up = Esplora.readButton(SWITCH_UP);
 int leftright = Esplora.readAccelerometer(X_AXIS);
 int updown = Esplora.readAccelerometer(Y_AXIS);
 //these are the values for the accelerometer.
 int xAxis = Esplora.readAccelerometer(X_AXIS);    // read the X axis
 int yAxis = Esplora.readAccelerometer(Y_AXIS);    // read the Y axis
 Serial.print("x: ");      // print the label for X
  Serial.print(xAxis);      // print the value for the X axis
  Serial.print("\ty: ");    // print a tab character, then the label for Y
  Serial.print(yAxis);      // print the value for the Y axis

   if(up == LOW)

   if(down == LOW)
   if(left == LOW)
   if(right == LOW)

 if (updown > -100)

 if (updown < 100)

 if (leftright < 100)

 if (leftright > -100)

 delay(1); //amount of time delay per loop, measured in milliseconds.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131