Arduino Leonardo using as a DDR pad freezing up

Hey there, I have an Arduino Leonardo that I have set up with pins 0-7 as pull-up resistors. I have it in keyboard mode and have the pins set up to send key presses when I ground the pin. Everything is working well until during a song when the “L” led comes on and the video starts lagging. The LED stays on until i hit the reset button on the board and then it goes away. I don’t have anything on pin 13 and i’m not sure what this LED is trying to indicate to me. I know that there may be some sort of issue with the dance app that I am using. i just need some help on where to look in the Arduino code to rule it out. Could it be that my arduino app on my PC is trying to communicate with the arduino at random times and is throwing it off?

I don’t know if this makes any difference but I have pins 8-11 set up as player 1 and player 2 start and back buttons in the code but I currently don’t have anything hooked up to them.

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click the “Reply” button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link that will allow you to make the attachment.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Thanks for the help. here is my current code.

/*
   This code contains the follow functions:
   - void setup(): Sets pins 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 to input with pull-up resistors enabled and begins Keyboard functionality
   - void loop(): Main loop - reads pin voltages and sends out corresponding keystrokes via USB

   - Keyboard layout for P1 is:
   Pin - Key - Function
   0   - w   - Up
   1   - a   - Left
   2   - s   - Down
   3   - d   - Right
   8   - q   - Back  -  Physical buttons not set up
   9   - e   - Start -  Physical buttons not set up

   - Keyboard layout for P2 is:
   Pin - Key - Function
   4   - i   - Up
   5   - j   - Left
   6   - k   - Down
   7   - l   - Right
   10  - u   - Back  -  Physical buttons not set up
   11  - i   - Start -  Physical buttons not set up
*/

/*
   Pinout:
   - "HIGH" voltage button contacts - pins 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
   - "GND" voltage button contacts - GND pin
*/

#include <Keyboard.h>

int P1upStatus = 1;
int P1upStatusPrev = 1;
int P1leftStatus = 1;
int P1leftStatusPrev = 1;
int P1downStatus = 1;
int P1downStatusPrev = 1;
int P1rightStatus = 1;
int P1rightStatusPrev = 1;
int P2upStatus = 1;
int P2upStatusPrev = 1;
int P2leftStatus = 1;
int P2leftStatusPrev = 1;
int P2downStatus = 1;
int P2downStatusPrev = 1;
int P2rightStatus = 1;
int P2rightStatusPrev = 1;
int P1quitStatus = 1;
int P1quitStatusPrev = 1;
int P1selectStatus = 1;
int P1selectStatusPrev = 1;
int P2quitStatus = 1;
int P2quitStatusPrev = 1;
int P2selectStatus = 1;
int P2selectStatusPrev = 1;


void setup()
{
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  Keyboard.begin();
}

void loop()
{
  P1upStatus = digitalRead(0);
  P1leftStatus = digitalRead(1);
  P1downStatus = digitalRead(2);
  P1rightStatus = digitalRead(3);
  P2upStatus = digitalRead(4);
  P2leftStatus = digitalRead(5);
  P2downStatus = digitalRead(6);
  P2rightStatus = digitalRead(7);
  P1quitStatus = digitalRead(8);
  P1selectStatus = digitalRead(9);
  P2quitStatus = digitalRead(10);
  P2selectStatus = digitalRead(11);

  //testing out delays to smooth out how many keypresses are happening.
  delay(10);


  // P1 UP ARROW PRESSED
  if (P1upStatus != P1upStatusPrev && P1upStatus == LOW)
  {
    Keyboard.press('w');
    P1upStatusPrev = P1upStatus;
  }
  // P1 UP ARROW RELEASED
  if (P1upStatus != P1upStatusPrev && P1upStatus == HIGH)
  {
    Keyboard.release('w');
    P1upStatusPrev = P1upStatus;
  }

  // P1 LEFT ARROW PRESSED
  if (P1leftStatus != P1leftStatusPrev && P1leftStatus == LOW)
  {
    Keyboard.press('a');
    P1leftStatusPrev = P1leftStatus;
  }
  // P1 LEFT ARROW RELEASED
  if (P1leftStatus != P1leftStatusPrev && P1leftStatus == HIGH)
  {
    Keyboard.release('a');
    P1leftStatusPrev = P1leftStatus;
  }

  // P1 DOWN ARROW PRESSED
  if (P1downStatus != P1downStatusPrev && P1downStatus == LOW)
  {
    Keyboard.press('s');
    P1downStatusPrev = P1downStatus;
  }
  // P1 DOWN ARROW RELEASED
  if (P1downStatus != P1downStatusPrev && P1downStatus == HIGH)
  {
    Keyboard.release('s');
    P1downStatusPrev = P1downStatus;
  }

  // P1 RIGHT ARROW PRESSED
  if (P1rightStatus != P1rightStatusPrev && P1rightStatus == LOW)
  {
    Keyboard.press('d');
    P1rightStatusPrev = P1rightStatus;
  }
  // P1 RIGHT ARROW RELEASED
  if (P1rightStatus != P1rightStatusPrev && P1rightStatus == HIGH)
  {
    Keyboard.release('d');
    P1rightStatusPrev = P1rightStatus;
  }
  // P1 Quit PRESSED
  if (P1quitStatus != P1quitStatusPrev && P1quitStatus == LOW)
  {
    Keyboard.press('q');
    P1quitStatusPrev = P1quitStatus;
  }
  // P1 Quit RELEASED
  if (P1quitStatus != P1quitStatusPrev && P1quitStatus == HIGH)
  {
    Keyboard.release('q');
    P1quitStatusPrev = P1quitStatus;
  }
  // P1 SELECT PRESSED
  if (P1selectStatus != P1selectStatusPrev && P1selectStatus == LOW)
  {
    Keyboard.press('e');
    P1selectStatusPrev = P1selectStatus;
  }
  // P1 SELECT RELEASED
  if (P1selectStatus != P1selectStatusPrev && P1selectStatus == HIGH)
  {
    Keyboard.release('e');
    P1selectStatusPrev = P1selectStatus;
  }
  // P2 UP ARROW PRESSED
  if (P2upStatus != P2upStatusPrev && P2upStatus == LOW)
  {
    Keyboard.press('i');
    P2upStatusPrev = P2upStatus;
  }
  // P2 UP ARROW RELEASED
  if (P2upStatus != P2upStatusPrev && P2upStatus == HIGH)
  {
    Keyboard.release('i');
    P2upStatusPrev = P2upStatus;
  }

  // P2 LEFT ARROW PRESSED
  if (P2leftStatus != P2leftStatusPrev && P2leftStatus == LOW)
  {
    Keyboard.press('j');
    P2leftStatusPrev = P2leftStatus;
  }
  // P2 LEFT ARROW RELEASED
  if (P2leftStatus != P2leftStatusPrev && P2leftStatus == HIGH)
  {
    Keyboard.release('j');
    P2leftStatusPrev = P2leftStatus;
  }

  // P2 DOWN ARROW PRESSED
  if (P2downStatus != P2downStatusPrev && P2downStatus == LOW)
  {
    Keyboard.press('k');
    P2downStatusPrev = P2downStatus;
  }
  // P2 DOWN ARROW RELEASED
  if (P2downStatus != P2downStatusPrev && P2downStatus == HIGH)
  {
    Keyboard.release('k');
    P2downStatusPrev = P2downStatus;
  }

  // P2 RIGHT ARROW PRESSED
  if (P2rightStatus != P2rightStatusPrev && P2rightStatus == LOW)
  {
    Keyboard.press('l');
    P2rightStatusPrev = P2rightStatus;
  }
  // P2 RIGHT ARROW RELEASED
  if (P2rightStatus != P2rightStatusPrev && P2rightStatus == HIGH)
  {
    Keyboard.release('l');
    P2rightStatusPrev = P2rightStatus;
  }
  // P2 Quit PRESSED
  if (P2quitStatus != P2quitStatusPrev && P2quitStatus == LOW)
  {
    Keyboard.press('u');
    P2quitStatusPrev = P2quitStatus;
  }
  // P2 Quit RELEASED
  if (P2quitStatus != P2quitStatusPrev && P2quitStatus == HIGH)
  {
    Keyboard.release('u');
    P2quitStatusPrev = P2quitStatus;
  }
  // P2 SELECT PRESSED
  if (P2selectStatus != P2selectStatusPrev && P2selectStatus == LOW)
  {
    Keyboard.press('o');
    P2selectStatusPrev = P2selectStatus;
  }
  // P2 SELECT RELEASED
  if (P2selectStatus != P2selectStatusPrev && P2selectStatus == HIGH)
  {
    Keyboard.release('o');
    P2selectStatusPrev = P2selectStatus;
  }

}

I don't spot anything suspicious in the code.

When the "L" LED goes on, is it steady on, or is it pulsing?

Steady on until I hit the reset button. Sometimes it goes unresponsive for a few seconds and sometimes it does not.

So I have done some more testing. I used a breadboard and some jumpers to move the Leonardo out of the dance pad enclosure to try to eliminate vibrations from jumping up and down on the pad as an issue. I continued to have this issue.

I then wrote some code (listed below) on my Arduino Uno to spam "LOW" signals to the Leonardo button pins at random to simulate lots and lots of inputs. As you can see, I have up to 3 signals at a time sent. I could not repeat the issue with this method. My setup with this test was to run pins 4-7 from the Uno as outputs, through a 1k resistor, in to pins 4-7 on the Leonardo. I used Pin 8 as the "On/Off" switch and jumped it to ground to switch on.

This leads me to thinking that there may be something wrong with my design of the buttons. When testing with the UNO i used the 1k resistors from the output pins to keep from damaging the LEONARDO inputs but there shouldn't be any need for me to add a resistor going to ground right? the LEONARDO should have a 20k resistor from 5V to the pin when it is designated as a pull up input. I tried running a 1k resister on the ground of the circuit anyway but that didn't resolve the issue.

It seems clear to me that there is something about these buttons that the Leonardo does not like. Is there any sort of error that would cause the board to light up the "L" LED when pin 13 isn't even activated in the code?

Arduino UNO code

int onOff = 1;
int randomNumber1 = 1;
int randomNumber2 = 1;
int randomNumber3 = 1;

void setup() {
  // put your setup code here, to run once:
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, INPUT_PULLUP);
  pinMode(13, OUTPUT);  // Just to turn that stupid "L" light off!
  digitalWrite(1ijkl3, LOW);// Just to turn that stupid "L" light off!
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  pinMode(0, INPUT);
  randomSeed(analogRead(0));
  
}

void loop() {
  // put your main code here, to run repeatedly:
  onOff = digitalRead(8);
  randomNumber1 = random(4, 8);
  randomNumber2 = random(4, 8);
  randomNumber3 = random(4, 8);
  if(onOff == LOW)
  {
    digitalWrite(randomNumber1, LOW); //press
    delay(10);
    digitalWrite(randomNumber2, LOW);  //press
    delay(10);
    digitalWrite(randomNumber3, LOW);  //press
    delay(10);
    digitalWrite(randomNumber1, HIGH); //release
    delay(10);
    digitalWrite(randomNumber2, HIGH);  //release
    delay(10);
    digitalWrite(randomNumber3, HIGH);  //release
    delay(10);

  }
 
}

Used my UNO to monitor the output of pin 13 when the LED comes on. It appears to just be on and not flashing at any frequency that the serial monitor can see. It is still odd that this happens even though pin 13 is not set up as an input or an output or anything by the program. Is it possible that PC7 (the pin on the chip connected to IO13) has some sort of additional feature that's kicking in for some reason?