Zumo Robot not reversing

Hi, i’m trying to create a script for my Zumo robot which will use WASD controls to go forward, turn left and right, and reverse. Using motor.setSpeeds seems to be working but using a hyphen before the variable or speed set doesn’t set the motor into reverse, it only goes forward still.

I have posted my code below if anyone would like to look - any help or guidance would be appreciated with this, many thanks!

#include <Wire.h>
#include <ZumoShield.h>
#include <ZumoMotors.h>

// Zumo32U4ButtonA buttonA;
// Documentation for the motors class:
// http://pololu.github.io/zumo-32u4-arduino-library/class_zumo32_u4_motors.html
ZumoMotors motors;

#define QTR_THRESHOLD  1500
#define NUM_SENSORS 6

#define MOTOR_SPEED 100
bool onOff = true;
unsigned int sensor_values[NUM_SENSORS];

ZumoReflectanceSensorArray sensors(QTR_NO_EMITTER_PIN);

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

void loop() {


  while (Serial1.available()>0) {
    
    int direction = Serial1.read();
    Serial.print("Got message: ");
    Serial.println(direction);
    String name ="";

    switch (direction){
      case'w': case 'W':
      name = "Forward";
      motors.setSpeeds(MOTOR_SPEED, MOTOR_SPEED);
      delay(250);
      motors.setSpeeds(0, 0);
      break;
      
      case'a': case 'A':
      name = "Left";
      motors.setSpeeds(-MOTOR_SPEED, MOTOR_SPEED);
      delay(115);
      motors.setSpeeds(0, 0);
      break;
      
      case'd': case 'D':
      name = "Right";
      motors.setSpeeds(MOTOR_SPEED, -MOTOR_SPEED);
      delay(115);
      motors.setSpeeds(0, 0);
      break;
      
      case's': case 'S':
      name = "Backwards";
      motors.setSpeeds(-MOTOR_SPEED, -MOTOR_SPEED);
      delay(250);
      motors.setSpeeds(0, 0);
      break;

      case'z': case 'Z':
      name = "Stop";
      motors.setSpeeds(0, 0);
      break;
    }
 }
}

Hello.

We make two versions of the Zumo Robot: the Zumo 32U4 Robot and the Zumo Robot for Arduino; which one are you using?

I didn’t see anything obviously wrong with your code. Which version of the Arduino IDE and Zumo library are you using? Depending how you installed the ZumoShield library, you can find the version number through the Arduino’s Library Manager or the README file in the ZumoShield library folder, which can be found in the \libraries folder under your Arduino sketchbook directory. You can find the sketchbook directory by selecting File -> Preferences in the Arduino IDE.

- Amanda