Problem with building code for Arduino Pro Micro

I have implemented the project as the link below.

Since I can not afford teensy 2.0, I have to buy arduino Pro Micro instead. I think it would be feasible.

However, following the instructions, i can not building code for this board. When build, issue the error in the JoyStick library directly from the setup() function.

Who can help me with the error and how to fix it? Or show me the same way I can do it.


Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to [u]item #7 about how to post your code.[/u] It will be formatted in a scrolling window that makes it easier to read.

We need to see your code and the error message it generates.

Thanks.. Tom.. :)

Hi Tom.

Thank for anser.

This my code.

//  G25 shifter to USB interface
//  based on a Teensy 2.0
//  3 operating modes
//  - H-pattern shifter
//  - Sequential shifter
//  - Analog handrake

//  G25 shifter pinout
//  DB9  Color    Shifter Description       Teensy
//  1    Black    1       +5V               +5V
//  2    Grey     7       Button Data       pin 17
//  3    Yellow   5       Button !CS & !PL  pin 18
//  4    Orange   3       Shifter X axis    pin 21 (A0)
//  5    Red      2       SPI input 
//  6    White    8       GND               GND
//  7    Purple   6       Button Clock      pin 19
//  8    Green    4       Shifter Y axis    pin 20 (A1)
//  9    Black    1       +5V

// Teensy pin definitions
#define LED_PIN            11
#define DATA_IN_PIN        17
#define MODE_PIN           18
#define CLOCK_PIN          19
#define X_AXIS_PIN         20
#define Y_AXIS_PIN         21

// H-shifter mode analog axis thresholds
#define HS_XAXIS_12        400
#define HS_XAXIS_56        600
#define HS_YAXIS_135       800
#define HS_YAXIS_246       300

// Sequential shifter mode analog axis thresholds
#define SS_UPSHIFT_BEGIN   670
#define SS_UPSHIFT_END     600
#define SS_DOWNSHIFT_END   500

// Handbrake mode analog axis limits
#define HB_MAXIMUM         530
#define HB_MINIMUM         400
#define HB_RANGE           (HB_MAXIMUM-HB_MINIMUM)

// Digital inputs definitions
#define DI_REVERSE         1
#define DI_MODE            3
#define DI_RED_RIGHT       6
#define DI_RED_LEFT        7
#define DI_BLACK_TOP       8
#define DI_BLACK_RIGHT     9
#define DI_BLACK_LEFT      10
#define DI_BLACK_BOTTOM    11
#define DI_DPAD_RIGHT      12
#define DI_DPAD_LEFT       13
#define DI_DPAD_BOTTOM     14
#define DI_DPAD_TOP        15

// Shifter state
#define DOWN_SHIFT         -1
#define NO_SHIFT           0
#define UP_SHIFT           1

// Shifter mode
#define SHIFTER_MODE       0
#define HANDBRAKE_MODE     1

// LED blink counter
int led=0;

// Shifter state
int shift=NO_SHIFT;

// Handbrake mode
int mode=SHIFTER_MODE;

// Called at startup
// Must initialize hardware and software modules
void setup()
  // G25 shifter analog inputs configuration 
  pinMode(X_AXIS_PIN, INPUT_PULLUP);   // X axis
  pinMode(Y_AXIS_PIN, INPUT_PULLUP);   // Y axis
  // G25 shift register interface configuration 
  pinMode(DATA_IN_PIN, INPUT);         // Data in
  pinMode(MODE_PIN, OUTPUT);           // Parallel/serial mode
  pinMode(CLOCK_PIN, OUTPUT);          // Clock
  // LED output mode configuration 
  pinMode(LED_PIN, OUTPUT);            // LED
  // Virtual joystick configuration 
  Joystick.useManualSend(true);        // Joystick output is synchronized
  // Virtual serial interface configuration 
  // Virtual joystick initialization 
  // Digital outputs initialization
  digitalWrite(LED_PIN, LOW);
  digitalWrite(MODE_PIN, HIGH);
  digitalWrite(CLOCK_PIN, HIGH); 

// Called in a loop after initialization
void loop() 
  // Reading of button states from G25 shift register
  int b[16];
  digitalWrite(MODE_PIN, LOW);         // Parallel mode: inputs are read into shift register
  delayMicroseconds(10);               // Wait for signal to settle
  digitalWrite(MODE_PIN, HIGH);        // Serial mode: data bits are output on clock falling edge
  for(int i=0; i<16; i++)              // Iteration over both 8 bit registers
    digitalWrite(CLOCK_PIN, LOW);      // Generate clock falling edge
    delayMicroseconds(10);             // Wait for signal to settle
    b[i]=digitalRead(DATA_IN_PIN);     // Read data bit and store it into bit array
    digitalWrite(CLOCK_PIN, HIGH);     // Generate clock rising edge
    delayMicroseconds(10);             // Wait for signal to settle

  // Reading of shifter position
  int x=analogRead(0);                 // X axis
  int y=analogRead(1);                 // Y axis
  // Handbrake mode logic
  if(b[DI_RED_CENTERLEFT]!=0)          // Is left center red button depressed?
    if(b[DI_RED_CENTERRIGHT]!=0)       // Is right center red button also depressed?
      if(b[DI_RED_RIGHT]!=0)           // Is rightmost red button also depressed?
        mode=HANDBRAKE_MODE;           // Handbrake mode is activated if the 3 rightmost 
      }                                // red buttons are depressed
      if(b[DI_RED_LEFT]!=0)            // Is leftmost red button also depressed?
        mode=SHIFTER_MODE;             // Handbrake mode is deactivated if the 3 leftmost
      }                                // red buttons are depressed
  // Current gear calculation
  int gear=0;                          // Default value is neutral

  if(b[DI_MODE]==0)                    // H-shifter mode?
    if(x<HS_XAXIS_12)                  // Shifter on the left?
      if(y>HS_YAXIS_135) gear=1;       // 1st gear
      if(y<HS_YAXIS_246) gear=2;       // 2nd gear
    else if(x>HS_XAXIS_56)             // Shifter on the right?
      if(y>HS_YAXIS_135) gear=5;       // 5th gear
      if(y<HS_YAXIS_246) gear=6;       // 6th gear
    else                               // Shifter is in the middle
      if(y>HS_YAXIS_135) gear=3;       // 3rd gear
      if(y<HS_YAXIS_246) gear=4;       // 4th gear
  else                                 // Sequential mode 
    if(mode==SHIFTER_MODE)             // Shifter mode?
      if(shift==NO_SHIFT)              // Current state: no shift
        if(y>SS_UPSHIFT_BEGIN)         // Shifter to the front?
          gear=1;                      // Shift-up
          shift=UP_SHIFT;              // New state: up-shift
        if(y<SS_DOWNSHIFT_BEGIN)       // Shifter to the rear?
          gear=2;                      // Shift-down
          shift=DOWN_SHIFT;            // New state: down-shift
      if(shift==UP_SHIFT)              // Current state: up-shift?
        if(y>SS_UPSHIFT_END) gear=1;   // Beyond lower up-shift threshold: up-shift
        else shift=NO_SHIFT;           // Else new state: no shift
      if(shift==DOWN_SHIFT)            // Current state: down-shift
        if(y<SS_DOWNSHIFT_END) gear=2; // Below higher down-shift threshold: down-shift
        else shift=0;                  // Else new state: no shift
    else                               // Handbrake mode
      if(y<HB_MINIMUM) y=HB_MINIMUM;   // Clip minimum position
      if(y>HB_MAXIMUM) y=HB_MAXIMUM;   // Clip maximum position
      long offset=(long)y-HB_MINIMUM;
      y=(int)(offset*1023/HB_RANGE);   // Scale input between minimum and maximum clip position
      Joystick.X(y);                   // Set handbrake analog output
      gear=0;                          // No gear engaged: neutral
  if(gear!=6) b[DI_REVERSE]=0;         // Reverse gear is allowed only on 6th gear position
  if(b[DI_REVERSE]==1) gear=0;         // 6th gear is deactivated if reverse gear is engaged
  // Release virtual buttons for all gears
  Joystick.button(1, LOW);
  Joystick.button(2, LOW);
  Joystick.button(3, LOW);
  Joystick.button(4, LOW);
  Joystick.button(5, LOW);
  Joystick.button(6, LOW);
  // Depress virtual button for current gear
  if(gear>0) Joystick.button(gear, HIGH);
  // Set state of virtual buttons for all the physical buttons (including reverse)
  for(int i=0; i<16; i++) Joystick.button(7+i, b[i]);
  // Write new virtual joystick state
  // Write inputs and outputs (remove comments to debug)
  Serial.print(" X axis: ");
  Serial.print(" Y axis: ");
  Serial.print(" Digital inputs: ");
  for(int i=0; i<16; i++)Serial.print(b[i]);
  Serial.print(" ");
  Serial.print(" Gear: ");
  Serial.print(" Mode: ");
  Serial.print(" Shift: ");

  // Blink the on-board LED
  if(++led==100) led=0;                     // Period is 100 cycles * 10ms = 1s
  if(led==0) digitalWrite(LED_PIN, LOW);    // LED is off for 50 cycles
  if(led==50) digitalWrite(LED_PIN, HIGH);  // LED is on for 50 cycles 
  // Wait
  delay(10);                                // Wait for 10ms

Please help. Thank so muck.
Best regards.

Hi, I think you will find the teensy provides a few built in features that the Micro Pro does not. Including a joystick type port. I am not an expert in teensy, but I notice the code uses joystick statements, without a library needed.

Tom... :)

While the Teensy and Micro use the same MCU, the pinouts are very different, on the Teensy, pin 19 is A4, on Micro, it's 21, A3, but they are both PF4 (port F, pin 4), try using the pinouts and schematics to cross reference, using the Atmel pin names (PB1, PC3, etc.).

Dear Tom, edgemoron

Thank for answer.

I do not think the problem is due to pinout. I tried instead. The problem is that when build code is encountered error in the command line contains JoinStick. I also think the problem is due to the library. I do not know which library to use instead. Have you idea for me. Who can help me ?


when build code is encountered error in the command line contains JoinStick.

Post ALL the error messages (in code tags </>).