Using PS4 controller to activate motors on Arduino UNO

Dear reader,

for school I have to make a contraption that moves via electrical motors. I wanted to use a PS4 controller, and make it so I can adjust the speed and direction of said motors. However, so far I have not even been able to turn on LEDs connected to the Arduino UNO using a PS4 controller. I connected the PS4 controller using a bluetooth adapter on a USB Host Shield, which I plugged directly onto my Arduino UNO board. With the example program I can only alter things on the PS4 controller (make it vibrate, turn on / off lights on the controller itself), but, like I said, cannot activate things on my board with the PS4 controller.

Is there a way to fix this?

Thanks in advance!

which one?

It is included in a library I downloaded.

/*
Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/

#include <PS4BT.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so

/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);

// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;

void setup() {
Serial.begin(115200);
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); // Halt
}
Serial.print(F("\r\nPS4 Bluetooth Library Started"));
}
void loop() {
Usb.Task();

if (PS4.connected()) {
if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS4.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS4.getAnalogHat(LeftHatY));
Serial.print(F("\tRightHatX: "));
Serial.print(PS4.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
Serial.print(PS4.getAnalogHat(RightHatY));
}

if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller
  Serial.print(F("\r\nL2: "));
  Serial.print(PS4.getAnalogButton(L2));
  Serial.print(F("\tR2: "));
  Serial.print(PS4.getAnalogButton(R2));
}
if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
  PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
oldL2Value = PS4.getAnalogButton(L2);
oldR2Value = PS4.getAnalogButton(R2);

if (PS4.getButtonClick(PS)) {
  Serial.print(F("\r\nPS"));
  PS4.disconnect();
}
else {
  if (PS4.getButtonClick(TRIANGLE)) {
    Serial.print(F("\r\nTriangle"));
    PS4.setRumbleOn(RumbleLow);
  }
  if (PS4.getButtonClick(CIRCLE)) {
    Serial.print(F("\r\nCircle"));
    PS4.setRumbleOn(RumbleHigh);
  }
  if (PS4.getButtonClick(CROSS)) {
    Serial.print(F("\r\nCross"));
    PS4.setLedFlash(10, 10); // Set it to blink rapidly
  }
  if (PS4.getButtonClick(SQUARE)) {
    Serial.print(F("\r\nSquare"));
    PS4.setLedFlash(0, 0); // Turn off blinking
  }

  if (PS4.getButtonClick(UP)) {
    Serial.print(F("\r\nUp"));
    PS4.setLed(Red);
  } if (PS4.getButtonClick(RIGHT)) {
    Serial.print(F("\r\nRight"));
    PS4.setLed(Blue);
  } if (PS4.getButtonClick(DOWN)) {
    Serial.print(F("\r\nDown"));
    PS4.setLed(Yellow);
  } if (PS4.getButtonClick(LEFT)) {
    Serial.print(F("\r\nLeft"));
    PS4.setLed(Green);
  }

  if (PS4.getButtonClick(L1))
    Serial.print(F("\r\nL1"));
  if (PS4.getButtonClick(L3))
    Serial.print(F("\r\nL3"));
  if (PS4.getButtonClick(R1))
    Serial.print(F("\r\nR1"));
  if (PS4.getButtonClick(R3))
    Serial.print(F("\r\nR3"));

  if (PS4.getButtonClick(SHARE))
    Serial.print(F("\r\nShare"));
  if (PS4.getButtonClick(OPTIONS)) {
    Serial.print(F("\r\nOptions"));
    printAngle = !printAngle;
  }
  if (PS4.getButtonClick(TOUCHPAD)) {
    Serial.print(F("\r\nTouchpad"));
    printTouch = !printTouch;
  }

  if (printAngle) { // Print angle calculated using the accelerometer only
    Serial.print(F("\r\nPitch: "));
    Serial.print(PS4.getAngle(Pitch));
    Serial.print(F("\tRoll: "));
    Serial.print(PS4.getAngle(Roll));
  }

  if (printTouch) { // Print the x, y coordinates of the touchpad
    if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad
      Serial.print(F("\r\n"));
    for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers
      if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad
        Serial.print(F("X")); Serial.print(i + 1); Serial.print(F(": "));
        Serial.print(PS4.getX(i));
        Serial.print(F("\tY")); Serial.print(i + 1); Serial.print(F(": "));
        Serial.print(PS4.getY(i));
        Serial.print(F("\t"));
      }
    }
  }
}

}
}

I can't see anything in that code that makes any attempt at all to set up or control any LEDs or motors connected to the Arduino. Where do you think that code is?

Steve

What I posted before was the original program. Afterwards, I tried altering it by implementing the following code:

Before void setup() I defined the following:
const int redLEDPin = 11;
const int blueLEDPin = 10;
const int greenLEDPin = 9;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

Then in void setup() I included whether the pins were INPUT / OUTPUT:

pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);

Then in void loop() I changed

if (PS4.getButtonClick(TRIANGLE)) {
Serial.print(F("\r\nTriangle"));
PS4.setRumbleOn(RumbleLow);
}
if (PS4.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle"));
PS4.setRumbleOn(RumbleHigh);
}
if (PS4.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross"));
PS4.setLedFlash(10, 10); // Set it to blink rapidly

to

if (PS4.getButtonClick(TRIANGLE)) {
Serial.print(F("\r\nTriangle"));
redValue = 256;
greenValue = 0;
blueValue = 0;
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
if (PS4.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle"));
redValue = 0;
greenValue = 256;
blueValue = 0;
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
if (PS4.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross"));
redValue = 0;
greenValue = 0;
blueValue = 256;
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}

I hooked it up to a 4-pin rgb-LED as shown in the attached photo

I tried it again today and this time I could change the colour. TRIANGLE and CIRCLE did not do anything. Strangely, the colour changed to red when I pressed CROSS (I would've expected it to change to blue). After this, It would not change any more.

Check the max value for analogWrite. I recall it is 255, not 256 but it has been a while since I used PWM. 256 probably wraps around back to 0.

Oh you are right, that may have definitely played a part. Another problem is that the LED starts out very bright, even though it's initial values are set to 0.

Something else I've noticed is the program stops working right after 'analogWrite' is called. When this happens there is also no indication that the Arduino is receiving signals (the orange light doesn't flash anymore; it used to flash whenever a button was pressed). With 'digitalWrite' the rest of the program does keep working, but then the colour of the LED doesn't change (because it has analog pins).

So post your current COMPLETE program. You may have accidentally changed or left out something your snippets don't show.

Steve

To save some lines of code, I moved the 'analogWrite' to the bottom. In my mind, it should still work the same.

/*
 Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
 For more information visit my blog: http://blog.tkjelectronics.dk/ or
 send me an e-mail:  kristianl@tkjelectronics.com
 */

#include <PS4BT.h>
#include <usbhub.h>

const int redLEDPin = 11;
const int blueLEDPin = 10;
const int greenLEDPin = 9;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so

/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);

// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;

void setup() {
  Serial.begin(115200);

  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
  
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); // Halt
  }
  Serial.print(F("\r\nPS4 Bluetooth Library Started"));
}
void loop() {
  Usb.Task();

  if (PS4.connected()) {
    if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) {
      Serial.print(F("\r\nLeftHatX: "));
      Serial.print(PS4.getAnalogHat(LeftHatX));
      Serial.print(F("\tLeftHatY: "));
      Serial.print(PS4.getAnalogHat(LeftHatY));
      Serial.print(F("\tRightHatX: "));
      Serial.print(PS4.getAnalogHat(RightHatX));
      Serial.print(F("\tRightHatY: "));
      Serial.print(PS4.getAnalogHat(RightHatY));
    }

    if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller
      Serial.print(F("\r\nL2: "));
      Serial.print(PS4.getAnalogButton(L2));
      Serial.print(F("\tR2: "));
      Serial.print(PS4.getAnalogButton(R2));
    }
    if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
      PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
    oldL2Value = PS4.getAnalogButton(L2);
    oldR2Value = PS4.getAnalogButton(R2);

    if (PS4.getButtonClick(PS)) {
      Serial.print(F("\r\nPS"));
      PS4.disconnect();
    }
    else {
      if (PS4.getButtonClick(TRIANGLE)) {
        Serial.print(F("\r\nTriangle"));
        redValue = 255;
        greenValue = 0;
        blueValue = 0;
      }
      if (PS4.getButtonClick(CIRCLE)) {
        Serial.print(F("\r\nCircle"));
        redValue = 0;
        greenValue = 255;
        blueValue = 0;
      }
      if (PS4.getButtonClick(CROSS)) {
        Serial.print(F("\r\nCross"));
        redValue = 0;
        greenValue = 0;
        blueValue = 255;
      }
      if (PS4.getButtonClick(SQUARE)) {
        Serial.print(F("\r\nSquare"));
      }

      if (PS4.getButtonClick(UP)) {
        Serial.print(F("\r\nUp"));
        PS4.setLed(Red);
      } if (PS4.getButtonClick(RIGHT)) {
        Serial.print(F("\r\nRight"));
        PS4.setLed(Blue);
      } if (PS4.getButtonClick(DOWN)) {
        Serial.print(F("\r\nDown"));
        PS4.setLed(Yellow);
      } if (PS4.getButtonClick(LEFT)) {
        Serial.print(F("\r\nLeft"));
        PS4.setLed(Green);
      }

      if (PS4.getButtonClick(L1))
        Serial.print(F("\r\nL1"));
      if (PS4.getButtonClick(L3))
        Serial.print(F("\r\nL3"));
      if (PS4.getButtonClick(R1))
        Serial.print(F("\r\nR1"));
      if (PS4.getButtonClick(R3))
        Serial.print(F("\r\nR3"));

      if (PS4.getButtonClick(SHARE))
        Serial.print(F("\r\nShare"));
      if (PS4.getButtonClick(OPTIONS)) {
        Serial.print(F("\r\nOptions"));
        printAngle = !printAngle;
      }
      if (PS4.getButtonClick(TOUCHPAD)) {
        Serial.print(F("\r\nTouchpad"));
        printTouch = !printTouch;
      }

      if (printAngle) { // Print angle calculated using the accelerometer only
        Serial.print(F("\r\nPitch: "));
        Serial.print(PS4.getAngle(Pitch));
        Serial.print(F("\tRoll: "));
        Serial.print(PS4.getAngle(Roll));
      }

      if (printTouch) { // Print the x, y coordinates of the touchpad
        if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad
          Serial.print(F("\r\n"));
        for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers
          if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad
            Serial.print(F("X")); Serial.print(i + 1); Serial.print(F(": "));
            Serial.print(PS4.getX(i));
            Serial.print(F("\tY")); Serial.print(i + 1); Serial.print(F(": "));
            Serial.print(PS4.getY(i));
            Serial.print(F("\t"));
          }
        }
      }
    }
  }
  analogWrite(redLEDPin, redValue);
  analogWrite(greenLEDPin, greenValue);
  analogWrite(blueLEDPin, blueValue);
}

To me it makes no sense at all to keep throwing analogWrites at the LED every time round loop() whether the PS4 is even connected or any button at all has been pressed.

But do you still get the same results? Does it really only go once round the loop() and then stop working? If not when does it stop, what do the Serial.prints show it did last? At one point you said that the LED is very bright (presumably white) when all the values are zero. Is that still happening? Can you try it with 3 separate LEDs instead of an RGB LED.

Steve

Fair enough, not every loop a value has to be assigned to the LEDs. I switched to 3 seperate LEDs instead of one RGB LED, and changed 'analogWrite' to 'digitalWrite'. I'll include the code below. What happens now is as follows:
While uploading the program to the Arduino, the green LED is on and the blue and red LEDs are off.
When uploading has finished, the green LED is off, the blue and red are on.
pressing CIRCLE / TRIANGLE / CROSS does not change anything, but the program keeps working (all other buttons execute their functions as expected and an orange light flashes whenever a button is pressed). EVERY button-press is logged (via Serial.prints), including CIRCLE / TRIANGLE / CROSS.

I tried putting the following in void setup() to have them all off initially, but it had no effect.
(it also probably isn't proper to put something like this in void setup() ):
digitalWrite(redLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
digitalWrite(blueLEDPin, LOW);

To be sure I didn't make any mistakes, I'll include another photo of the setup.

And the code:

#include <PS4BT.h>
#include <usbhub.h>

const int redLEDPin = 11;
const int blueLEDPin = 10;
const int greenLEDPin = 9;

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so

/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);

// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;

void setup() {
Serial.begin(115200);

pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);

digitalWrite(redLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
digitalWrite(blueLEDPin, LOW);

#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); // Halt
}
Serial.print(F("\r\nPS4 Bluetooth Library Started"));
}
void loop() {
Usb.Task();

if (PS4.connected()) {
if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS4.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS4.getAnalogHat(LeftHatY));
Serial.print(F("\tRightHatX: "));
Serial.print(PS4.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
Serial.print(PS4.getAnalogHat(RightHatY));
}

if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller
  Serial.print(F("\r\nL2: "));
  Serial.print(PS4.getAnalogButton(L2));
  Serial.print(F("\tR2: "));
  Serial.print(PS4.getAnalogButton(R2));
}
if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
  PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
oldL2Value = PS4.getAnalogButton(L2);
oldR2Value = PS4.getAnalogButton(R2);

if (PS4.getButtonClick(PS)) {
  Serial.print(F("\r\nPS"));
  PS4.disconnect();
}
else {
  if (PS4.getButtonClick(TRIANGLE)) {
    Serial.print(F("\r\nTriangle"));
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
    digitalWrite(blueLEDPin, LOW);
  }
  if (PS4.getButtonClick(CIRCLE)) {
    Serial.print(F("\r\nCircle"));
    digitalWrite(redLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
    digitalWrite(blueLEDPin, LOW);
  }
  if (PS4.getButtonClick(CROSS)) {
    Serial.print(F("\r\nCross"));
    digitalWrite(redLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
    digitalWrite(blueLEDPin, HIGH);
  }
  if (PS4.getButtonClick(SQUARE)) {
    Serial.print(F("\r\nSquare"));
  }

  if (PS4.getButtonClick(UP)) {
    Serial.print(F("\r\nUp"));
    PS4.setLed(Red);
  } if (PS4.getButtonClick(RIGHT)) {
    Serial.print(F("\r\nRight"));
    PS4.setLed(Blue);
  } if (PS4.getButtonClick(DOWN)) {
    Serial.print(F("\r\nDown"));
    PS4.setLed(Yellow);
  } if (PS4.getButtonClick(LEFT)) {
    Serial.print(F("\r\nLeft"));
    PS4.setLed(Green);
  }

  if (PS4.getButtonClick(L1))
    Serial.print(F("\r\nL1"));
  if (PS4.getButtonClick(L3))
    Serial.print(F("\r\nL3"));
  if (PS4.getButtonClick(R1))
    Serial.print(F("\r\nR1"));
  if (PS4.getButtonClick(R3))
    Serial.print(F("\r\nR3"));

  if (PS4.getButtonClick(SHARE))
    Serial.print(F("\r\nShare"));
  if (PS4.getButtonClick(OPTIONS)) {
    Serial.print(F("\r\nOptions"));
    printAngle = !printAngle;
  }
  if (PS4.getButtonClick(TOUCHPAD)) {
    Serial.print(F("\r\nTouchpad"));
    printTouch = !printTouch;
  }

  if (printAngle) { // Print angle calculated using the accelerometer only
    Serial.print(F("\r\nPitch: "));
    Serial.print(PS4.getAngle(Pitch));
    Serial.print(F("\tRoll: "));
    Serial.print(PS4.getAngle(Roll));
  }

  if (printTouch) { // Print the x, y coordinates of the touchpad
    if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad
      Serial.print(F("\r\n"));
    for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers
      if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad
        Serial.print(F("X")); Serial.print(i + 1); Serial.print(F(": "));
        Serial.print(PS4.getX(i));
        Serial.print(F("\tY")); Serial.print(i + 1); Serial.print(F(": "));
        Serial.print(PS4.getY(i));
        Serial.print(F("\t"));
      }
    }
  }
}

}
}

When using 'analogWrite' with the seperate 3 LEDs, progress occurs!

Context:
-The blue and red LEDs are still very bright at all times.
-When CIRCLE is pressed, only the green LED should shine bright.
-When TRIANGLE is pressed, only the red LED should shine bright.
-When CROSS is pressed, only the blue LED should shine bright.

When I press CIRCLE, the green LED starts shining very faintly (even though I used "analogWrite(greenLEDPin, 255);"
The program keeps working, and when I press TRIANGLE or CROSS the green LED turns off again.
(So I can make the green LED turn on and off, as many times as I want)

I FIGURED IT OUT!

Apparently, it was the pins on the Arduino that the LEDs were wired to. I changed the pins from 11, 10, 9 for red, blue, green to 4, 3, 2, respectively. NOW IT WORKS!

Thank you all so much for the help and patience!

Good job! Pins 11 (MOSI) and 10 (SS) are used by the USB host shield for SPI so that is why moving to other pins works.