Go Down

Topic: Errors when compiling Pi Play controller (Read 215 times) previous topic - next topic

Hi all:

Been trying to upload this sketch here and I cannot find anything wrong with it:

c/*
  Esplora Kart

  This sketch turns the Esplora into a PC game pad.

  It uses the both the analog joystick and the four switches.
  By moving the joystick in a direction or by pressing a switch,
  the PC will "see" that a key is pressed. If the PC is running
  a game that has keyboard input, the Esplora can control it.
 
  The default configuration is suitable for SuperTuxKart, an
  open-source racing game. It can be downloaded from
  http://supertuxkart.sourceforge.net/ .

  Created on 22 november 2012
  By Enrico Gueli <enrico.gueli@gmail.com>
*/


#include <Esplora.h>

/*
  You're going to handle eight different buttons. You'll use arrays,
  which are ordered lists of variables with a fixed size. Each array
  has an index (counting from 0) to keep track of the position
  you're reading in the array, and each position can contain a number.
 
  This code uses three different arrays: one for the buttons you'll read;
  a second to hold the current states of those buttons; and a third to hold
  the keystrokes associated with each button.
 */

/*
  This array holds the last sensed state of each of the buttons
  you're reading.
  Later in the code, you'll read the button states, and compare them
  to the previous states that are stored in this array. If the two
  states are different, it means that the button was either
  pressed or released.
 */
boolean buttonStates[8];

/*
  This array holds the names of the buttons being read.
  Later in the sketch, you'll use these names with
  the method Esplora.readButton(x), where x
  is one of these buttons.
 */
const byte buttons[] = {
  JOYSTICK_DOWN,
  JOYSTICK_LEFT,
  JOYSTICK_UP,
  JOYSTICK_RIGHT,
  SWITCH_RIGHT, // fire
  SWITCH_LEFT, // bend
  SWITCH_UP, // nitro
  SWITCH_DOWN, // look back
};

/*
  This array tells what keystroke to send to the PC when a
  button is pressed.
  If you look at this array and the above one, you can see that
  the "cursor down" keystroke is sent when the joystick is moved
  down, the "cursor up" keystroke when the joystick is moved up
  and so on.
*/
const char keystrokes[] = {
  KEY_DOWN_ARROW,
  KEY_LEFT_ARROW,
  KEY_UP_ARROW,
  KEY_RIGHT_ARROW,
  KEY_LEFT_ALT,
  ' ',
  KEY_RETURN,
  KEY_LEFT_CTRL
};

/*
  This is code is run only at startup, to initialize the
  virtual USB keyboard.
*/
void setup() {
  Keyboard.begin();
  Serial.begin(9600);
}

/*
  After setup() is finished, this code is run continuously.
  Here we continuously check if something happened with the
  buttons.
*/
void loop() {
 
  // Iterate through all the buttons:
  for (byte thisButton=0; thisButton<8; thisButton++) {
    boolean lastState = buttonStates[thisButton];
    boolean newState = Esplora.readButton(buttons[thisButton]);
    if (lastState != newState) { // Something changed!
      /*
        The Keyboard library allows you to "press" and "release" the
        keys as two distinct actions. These actions can be
        linked to the buttons we're handling.
       */
      if (newState == PRESSED) {
        Keyboard.press(keystrokes[thisButton]);
      }
      else if (newState == RELEASED) {
        Keyboard.release(keystrokes[thisButton]);
      }
    }

    // Store the new button state, so you can sense a difference later:
    buttonStates[thisButton] = newState;
  }
 
 
  /*
    Wait a little bit (50ms) between a check and another.
    When a mechanical switch is pressed or released, the
    contacts may bounce very rapidly. If the check is done too
    fast, these bounces may be confused as multiple presses and
    may lead to unexpected behaviour.
   */
  delay(50);

  int zAxis = Esplora.readAccelerometer(Z_AXIS);

  if (zAxis <= -120) {
    Keyboard.press(KEY_ESC);
    delay(50);
    Keyboard.release(KEY_ESC);
    delay(1000);
  }
 
  int slider = Esplora.readSlider();
 
  if (slider <= 500) {
 /*   Keyboard.press(KEY_TAB);
    delay(500);
    Keyboard.release(KEY_ESC);
    delay(1000);
   */
 
   delay(500);
   int slider = Esplora.readSlider();
   if (slider >= 501) {
     Keyboard.press(KEY_TAB);
     delay(50);
     Keyboard.release(KEY_TAB);
     delay(250);
   }   
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
}

It is a modified code of the EsploraKart and is suppose to work with MAME with PiPlay, but when I go to compile and upload I get a compile error and I have no clue what it means:

Arduino: 1.6.3 (Windows 7), Board: "Arduino Esplora"

PiPlayControl.ino:2:1: error: 'c' does not name a type

In file included from PiPlayControl.ino:21:0:

C:\Program Files\Arduino\libraries\Esplora\src/Esplora.h:64:29: error: 'JOYSTICK_BASE' was not declared in this scope

 const byte JOYSTICK_DOWN  = JOYSTICK_BASE;

                             ^

C:\Program Files\Arduino\libraries\Esplora\src/Esplora.h:65:29: error: 'JOYSTICK_BASE' was not declared in this scope

 const byte JOYSTICK_LEFT  = JOYSTICK_BASE+1;

                             ^

C:\Program Files\Arduino\libraries\Esplora\src/Esplora.h:66:29: error: 'JOYSTICK_BASE' was not declared in this scope

 const byte JOYSTICK_UP    = JOYSTICK_BASE+2;

                             ^

C:\Program Files\Arduino\libraries\Esplora\src/Esplora.h:67:29: error: 'JOYSTICK_BASE' was not declared in this scope

 const byte JOYSTICK_RIGHT = JOYSTICK_BASE+3;

                             ^

Error compiling.

I have add the JOYSTICK _BASE as I have believed was needed and still it doesn't compile. I am not getting what is going on here. Any ideas?

semipro

If you look right before the commented section, you can see the letter c. Just remove that.
c/*
  Esplora Kart

  This sketch turns the Esplora into a PC game pad.

  It uses the both the analog joystick and the four switches.
  By moving the joystick in a direction or by pressing a switch,
  the PC will "see" that a key is pressed. If the PC is running
  a game that has keyboard input, the Esplora can control it.
 
  The default configuration is suitable for SuperTuxKart, an
  open-source racing game. It can be downloaded from
  http://supertuxkart.sourceforge.net/ .

  Created on 22 november 2012
  By Enrico Gueli <enrico.gueli@gmail.com>
*/

After removing the c, the code compiled for me, so I am not sure why your's does not compile. I am using a different version of arduino though. Just remove the c and recompile. See if it compiles.

chummer1010

#2
Apr 26, 2015, 05:50 pm Last Edit: Apr 26, 2015, 05:51 pm by chummer1010
use code tags...
Code: [Select]
[code] [/code]
#include <cheesy.quote>

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!

Arduino
via Egeo 16
Torino, 10131
Italy