Unexpected output (A0) Uno R3

edited for clarity
When I push menu up or down, HTog gets inverted, which starts the horn beeping command. From what I can tell, nothing in the horn or horn button's routine even mentions up or down.

Detailed explanation on line 271.

code with comments that explain things:

#include <SoftwareSerial.h>
#include "SSD1306Ascii.h"

#define I2C_ADDRESS 0x3C//serial link to bike's controller
#define AGREE_TO_TERMS false//used in person 2's code to prevent/allow speeds above 19 mph
#define up 4//menu up
#define Horn_b 5//horn button
#define down 6//menu down
#define RTurn 7//right turn signal button
#define LTurn 8//left turn signal button
#define Brakes 12//brake light's button
#define RLED 9//right turn signal LED
#define LLED 10//left turn signal LED
#define Brakes_LED 11
#define Horn A0//actual horn/piezoelectric buzzer
#define RST_PIN -1//no idea. from person 3's code for setting up the serial link between arduino and display 

SSD1306AsciiAvrI2c oled;
SoftwareSerial mySerial(2, 3); // RX, TX

unsigned long RpreviousMillis = 0;//variable used for right turn signal delay
unsigned long LpreviousMillis = 0;//variable used for left turn signal delay
unsigned long HpreviousMillis = 0;//variable used for horn beeping delay
unsigned long HbpreviousMillis = 0;//variable used to keep track of horn button press length
unsigned long oledpreviousMillis = 0;//variable used for screen refresh rate (gets kinda weird if too quick)
const long interval = 500;//turn signal interval
int Tmax = 150;//max motor temperature (Celcius) considered "safe"
int speed_ = 0.0;//top actual speed
bool RState = 0;//is right turn signal on or off?
bool LState = 0;//is left turn signal on or off?
bool RTog = 0;//triggers right turn signal
bool LTog = 0;//triggers left turn signal
bool HTog = 0;//triggers horn beeping
bool sel = 0;//changes up/down function
bool up_var = 0;//is button pushed?
bool Horn_var = 0;//is button pushed?
bool down_var = 0;//is button pushed?
bool RTurn_var = 0;//is button pushed?
bool LTurn_var = 0;//is button pushed?
bool Brakes_var = 0;//is button pushed?
int TMPH = 15;//current max speed
int kmph = TMPH * 1.609;  //Convert mph to kmph
byte bA[] = {0xaa, 0x06, 0x06, kmph, 0x00, 0xbb}; //Initialize byte array
byte headlightsOn[] = {0xaa, 0x07, 0x06, 0x01, 0xaa, 0xbb};
byte headlightsOff[] = {0xaa, 0x07, 0x06, 0x00, 0xab, 0xbb};

//variables for text to display
String yel = String(11);
String blu1 = String(11);
String blu2 = String(11);
String blu3 = String(11);
//text end

//person 2's arduino to bike wizardry
int maxSpeedKM = 0;   // kmph
float speedRPM = 0.0; // RPM
float speed = (int(speedRPM * 43.98229715 * 10) / 10); //MPH
int temperature = 0;  // Celsius
int temperature_ = 0;
float voltage = 0.0f; // UNKNOWN
int odo = 0;          // unknown format
int runTime = 0;      // Minutes
int headlight = 0;    // 0x00 off | 0x10 on

int incoming;
int incomingArr[9];
int index = 0;

void printRegister( int arr[] ) {
  for (int i = 0; i < 9; i++) {
    if (arr[i] <= 0x0f)
      Serial.print(0);
    Serial.print(arr[i], HEX);
  }
    Serial.println(0xbb, HEX);
}

int checkSum(int inArray[], int arraySize) {
  int checksum = 0x00;
  for(int i = 0; i < arraySize - 2; i++)
    checksum ^= inArray[i];
  return checksum;
}
//person 2's code ends

void setup()
{ 
  //no clue why this is necessary
  #define RST_PIN -1
  #if RST_PIN >= 0
    oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
  #else
    oled.begin(&Adafruit128x64, I2C_ADDRESS);
  #endif
  //still no clue
  
  //text
  yel = String("-----------");
  blu1 = String(" MAX:" + String(TMPH) + "----");
  blu2 = String(" " + String(speed,1) + "-" + String(speed_,1));
  blu3 = String(" " + String(temperature) + "C-" + String(temperature_) + "C");
  //text

  oled.setFont(System5x7);
  oled.clear();
  oled.set2X();
  oled.println(yel);
  oled.println(blu1);
  oled.println(blu2);
  oled.println(blu3);

  pinMode(LLED,OUTPUT);
  pinMode(RLED,OUTPUT);
  pinMode(up,INPUT_PULLUP);
  pinMode(Horn_b,INPUT_PULLUP);
  pinMode(down,INPUT_PULLUP);
  pinMode(LTurn,INPUT_PULLUP);
  pinMode(RTurn,INPUT_PULLUP);
  pinMode(Brakes,INPUT_PULLUP);
  pinMode(Brakes_LED,OUTPUT);
  pinMode(Horn,OUTPUT);

  //person 2's stuff
  // Open serial communications 115200 BAUD
  Serial.begin(115200);
  while (!Serial) { ; }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);

  delay(200); // Wait for Jetson controller to boot
  
//read bike's controller start
  if (mySerial.available())
  {
      incoming = mySerial.read();
      if (incoming != 0xBB)
      {
        incomingArr[index] = incoming;
        index++;
      } 
      else 
      {
        
        if (checkSum(incomingArr, 10) == incomingArr[8])
        {
          if (incomingArr[1] == 0xA1)
          {
            speedRPM = (incomingArr[5-1] * 0xff) + incomingArr[6-1];
            temperature = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA2)
          {
            odo = incomingArr[5-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA3)
          {
            maxSpeedKM = incomingArr[4-1];
            runTime = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA4)
          {
            headlight = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA7)
          {
            printRegister(incomingArr);
          }
        }
        
        index = 0;
      }
  }
//read bike's controller end

  if (TMPH < 3)             // Only accept values higher than 3
  {
    kmph = 3;
  }
  if (kmph > 0xff && AGREE_TO_TERMS)    // Don't allow setting higher than 0xff (255)
  {
    kmph = 0xff;
  }
  if (kmph > 30 && !AGREE_TO_TERMS)     // If the user has not agreed to terms
  {
    kmph = 30;
  }                          // Do not accept speed higher than 19 mph (30 kmph)

  bA[3] = kmph;
    
  int SizeOfArray = sizeof(bA) / sizeof(bA[0]);
  bA[4] = checkSum(bA, SizeOfArray);  //Calculate and add the checksum to byte array
  
  for(int i = 0; i < SizeOfArray; i++)
  {
    //Write bytes serially to pin 3. This should be connected to the GREY wire of the Jetson Bolt Pro
    mySerial.write(bA[i]);
  }
}

byte checkSum(byte byteArray[], int arraySize)
{
  byte checksum = 0x00;
  for(int i = 0; i < arraySize - 2; i++)
    checksum ^= byteArray[i];
  return checksum;
}
//person 2's code end

void loop()
{
  up_var = !digitalRead(up);
  Horn_var = !digitalRead(Horn_b);
  down_var = !digitalRead(down);
  RTurn_var = !digitalRead(RTurn);//inverted reads in this section are to make on=1 and off=0
  LTurn_var = !digitalRead(LTurn);
  Brakes_var = digitalRead(Brakes);//brakes are already inverted
  unsigned long currentMillis = millis();
  
//read bike's controller start (pulled from person 2's code)
  if (mySerial.available())
  {
      incoming = mySerial.read();
      if (incoming != 0xBB)
      {
        incomingArr[index] = incoming;
        index++;
      } 
      else 
      {
        
        if (checkSum(incomingArr, 10) == incomingArr[8])
        {
          if (incomingArr[1] == 0xA1)
          {
            speedRPM = (incomingArr[5-1] * 0xff) + incomingArr[6-1];
            temperature = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA2)
          {
            odo = incomingArr[5-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA3)
          {
            maxSpeedKM = incomingArr[4-1];
            runTime = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA4)
          {
            headlight = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA7)
          {
            printRegister(incomingArr);
          }
        }
        
        index = 0;
      }
  }
//read bike's controller end (pulled from person 2's code)
  
/*problem area start
This is supposed to be set up to have a variable's value match the current
time until the button is pressed. This section should then do nothing until
the button is released and determine if the button was pressed for a short
duration (tap) or a long duration (hold). If it was a tap, routine 1 should be
the only one activated. If it was a hold, routine 2 should be the only one
activated. This works as intended with the horn button (Horn_b & Horn_var),
but the tap routine activates even when up/down are pressed for any length of time.
*/
//Horn button
  if (Horn_var == 0 && currentMillis - HbpreviousMillis < 1500 && currentMillis - HbpreviousMillis > 120)
  {
    HTog = !HTog;//short push (tap) tells horn to start beeping
  }
  if (Horn_var == 0 && currentMillis - HbpreviousMillis >= 1500)
  {
    sel = !sel;//long push (hold) changes function of up/down
  }
  if (Horn_var == 0)
  {
    HbpreviousMillis = currentMillis;//tries to match current time until button is pushed
  }
//Horn button end
//beep start
  if (HTog == 1 && currentMillis - HpreviousMillis >= 300)
  {
    digitalWrite(Horn,HIGH);
    delay(10);
    digitalWrite(Horn,LOW);
    HpreviousMillis = currentMillis;
  }
//beep end
//problem area end (hopefully)
  
  if (RTurn_var == 1 && LTurn_var == 0)
  {
    RTog = !RTog;//toggles right turn signal
    LTog = 0;//turns left turn signal off
    delay(250);//debounce
  }
  if (LTurn_var == 1 && RTurn_var == 0)
  {
    LTog = !LTog;//toggles left turn signal
    RTog = 0;//turns right turn signal off
    delay(250);//debounce
  }
  if (Brakes_var == 1)
  {
    analogWrite(Brakes_LED,255);//brake light is brighter
  }
  else
  {
    analogWrite(Brakes_LED,70);//running light is dimmer brake
  }
  
  if (RTog == 1 && currentMillis - RpreviousMillis >= interval && RState == 0)
  {//if right turn signal is off & routine is on, and wait time is correct, turns light on and makes sure left is off
    digitalWrite(RLED,HIGH);
    RState = 1;
    LState = 0;
    yel = "---------->";//updates screen line 1
    RpreviousMillis = currentMillis;
  }
  else if (RTog == 1 && currentMillis - RpreviousMillis >= interval && RState == 1)
  {//if right turn signal is on & routine is on, and wait time is correct, turns light off and makes sure left is off
    digitalWrite(RLED,LOW);
    RState = 0;
    LState = 0;
    RpreviousMillis = currentMillis;
  }
  
  if (LTog == 1 && currentMillis - LpreviousMillis >= interval && LState == 0)
  {//if left turn signal is off & routine is on, and wait time is correct, turns light on and makes sure right is off
    digitalWrite(LLED,HIGH);
    LState = 1;
    RState = 0;
    yel = "<----------";//updates screen line 1
    LpreviousMillis = currentMillis;
  }
  else if (LTog == 1 && currentMillis - LpreviousMillis >= interval  && LState == 1)
  {//if left turn signal is on & routine is on, and wait time is correct, turns light off and makes sure right is off
    digitalWrite(LLED,LOW);
    LState = 0;
    RState = 0;
    LpreviousMillis = currentMillis;
  }
  
  if (LTog == 0 && RTog == 0)
  {//if both turn signal routines are off, turns both LEDs off
    digitalWrite(LLED,LOW);
    digitalWrite(RLED,LOW);
    LState = 0;
    RState = 0;
    yel = "-----------";//updates screen line 1
  }
  
//menu
  if (sel == 0)
  {//menu mode 1 controlled by horn button hold
    blu1 = String(" MAX:" + String(TMPH) + "----");
    blu2 = String(">" + String(speed,1) + "-" + String(speed_,1));
    blu3 = String(">" + String(temperature) + "C-" + String(temperature_) + "C");
    if (up_var == 1 && up_var + down_var == 1)
    {
      speed_ = speed;//up resets highest speed (spedometer) to current speed (spedometer)
    }
    if (down_var == 1 && up_var + down_var == 1)
    {
      temperature_ = temperature;//down resets highest temperature reached to current temperature
    }
  }
  if (sel == 1)
  {//menu mode 2 controlled by horn button hold
    blu1 = String(">MAX:" + String(TMPH) + "----");
    blu2 = String(" " + String(speed,1) + "-" + String(speed_,1));
    blu3 = String(" " + String(temperature) + "C-" + String(temperature_) + "C");
    
    if (up_var == 1 && up_var + down_var == 1 && TMPH < 19)
    {//up raises max speed on motor
      TMPH = TMPH + 1;
      kmph = (TMPH) * 1.609;
      delay(250);
    }
    if (down_var == 1 && up_var + down_var == 1 && TMPH > 11)
    {//down lowers max speed on motor
      TMPH = TMPH - 1;
      kmph = (TMPH) * 1.609;
      delay(250);
    }
  }
//menu
  
  if (temperature >= Tmax && TMPH > 15)
  {//if temperature is too high, lowers max speed to 15 mph
    TMPH = 15;
    kmph = (TMPH) * 1.609;
    up_var = 0;
    down_var = 1;
  }

//more arduino to bike communication wizardry
  if (up_var + down_var == 1)
  {
     bA[3] = kmph;
    
    int SizeOfArray = sizeof(bA) / sizeof(bA[0]);
    bA[4] = checkSum(bA, SizeOfArray);  //Calculate and add the checksum to byte array
  
    for(int i = 0; i < SizeOfArray; i++)
    {
      //Write bytes serially to pin 3. This should be connected to the GREY wire of the Jetson Bolt Pro
      mySerial.write(bA[i]);
    }
  }
//wizardry ends
  
  if (currentMillis - oledpreviousMillis >= 500)
  {//if refresh rate reached, refreshes screen
    oled.clear();
    oled.println(yel);
    oled.println(blu1);
    oled.println(blu2);
    oled.println(blu3);
    oledpreviousMillis = currentMillis;
  }
}

better picture:

SSD1306Ascii.h is the default 4 pin oled library.

#include <SoftwareSerial.h>
#include "SSD1306Ascii.h"

#define I2C_ADDRESS 0x3C
#define AGREE_TO_TERMS false
#define up 4
#define Horn_b 5
#define down 6
#define RTurn 7
#define LTurn 8
#define Brakes 12
#define RLED 9
#define LLED 10
#define Brakes_LED 11
#define Horn A0
#define RST_PIN -1

SSD1306AsciiAvrI2c oled;
SoftwareSerial mySerial(2, 3); // RX, TX

unsigned long RpreviousMillis = 0;
unsigned long LpreviousMillis = 0;
unsigned long HpreviousMillis = 0;
unsigned long HbpreviousMillis = 0;
unsigned long oledpreviousMillis = 0;
const long interval = 500;
int Tmax = 150;
int speed_ = 0.0;
bool RState = 0;
bool LState = 0;
bool RTog = 0;
bool LTog = 0;
bool HTog = 0;
bool sel = 0;
bool up_var = 0;
bool Horn_var = 0;
bool down_var = 0;
bool RTurn_var = 0;
bool LTurn_var = 0;
bool Brakes_var = 0;
int TMPH = 15;
int kmph = TMPH * 1.609;  //Convert mph to kmph
byte bA[] = {0xaa, 0x06, 0x06, kmph, 0x00, 0xbb}; //Initialize byte array
byte headlightsOn[] = {0xaa, 0x07, 0x06, 0x01, 0xaa, 0xbb};
byte headlightsOff[] = {0xaa, 0x07, 0x06, 0x00, 0xab, 0xbb};
String yel = String(11);
String blu1 = String(11);
String blu2 = String(11);
String blu3 = String(11);

//read
int maxSpeedKM = 0;   // kmph
float speedRPM = 0.0; // RPM
float speed = (int(speedRPM * 43.98229715 * 10) / 10); //MPH
int temperature = 0;  // Celsius
int temperature_ = 0;
float voltage = 0.0f; // UNKNOWN
int odo = 0;          // unknown format
int runTime = 0;      // Minutes
int headlight = 0;    // 0x00 off | 0x10 on

int incoming;
int incomingArr[9];
int index = 0;

void printRegister( int arr[] ) {
  for (int i = 0; i < 9; i++) {
    if (arr[i] <= 0x0f)
      Serial.print(0);
    Serial.print(arr[i], HEX);
  }
    Serial.println(0xbb, HEX);
}

int checkSum(int inArray[], int arraySize) {
  int checksum = 0x00;
  for(int i = 0; i < arraySize - 2; i++)
    checksum ^= inArray[i];
  return checksum;
}
//read

void setup()
{ 
  #define RST_PIN -1
  #if RST_PIN >= 0
    oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
  #else
    oled.begin(&Adafruit128x64, I2C_ADDRESS);
  #endif
  
  yel = String("-----------");
  blu1 = String(" MAX:" + String(TMPH) + "----");
  blu2 = String(" " + String(speed,1) + "-" + String(speed_,1));
  blu3 = String(" " + String(temperature) + "C-" + String(temperature_) + "C");

  oled.setFont(System5x7);
  oled.clear();
  oled.set2X();
  oled.println(yel);
  oled.println(blu1);
  oled.println(blu2);
  oled.println(blu3);

  pinMode(LLED,OUTPUT);
  pinMode(RLED,OUTPUT);
  pinMode(up,INPUT_PULLUP);
  pinMode(Horn_b,INPUT_PULLUP);
  pinMode(down,INPUT_PULLUP);
  pinMode(LTurn,INPUT_PULLUP);
  pinMode(RTurn,INPUT_PULLUP);
  pinMode(Brakes,INPUT_PULLUP);
  pinMode(Brakes_LED,OUTPUT);
  pinMode(Horn,OUTPUT);

  
  // Open serial communications 115200 BAUD
  Serial.begin(115200);
  while (!Serial) { ; }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);

  delay(200); // Wait for Jetson controller to boot
  
//read
  if (mySerial.available())
  {
      incoming = mySerial.read();
      if (incoming != 0xBB)
      {
        incomingArr[index] = incoming;
        index++;
      } 
      else 
      {
        
        if (checkSum(incomingArr, 10) == incomingArr[8])
        {
          if (incomingArr[1] == 0xA1)
          {
            speedRPM = (incomingArr[5-1] * 0xff) + incomingArr[6-1];
            temperature = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA2)
          {
            odo = incomingArr[5-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA3)
          {
            maxSpeedKM = incomingArr[4-1];
            runTime = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA4)
          {
            headlight = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA7)
          {
            printRegister(incomingArr);
          }
        }
        
        index = 0;
      }
  }
//read

  if (TMPH < 3)             // Only accept values higher than 3
  {
    kmph = 3;
  }
  if (kmph > 0xff && AGREE_TO_TERMS)    // Don't allow setting higher than 0xff (255)
  {
    kmph = 0xff;
  }
  if (kmph > 30 && !AGREE_TO_TERMS)     // If the user has not agreed to terms
  {
    kmph = 30;
  }                          // Do not accept speed higher than 19 mph (30 kmph)

  bA[3] = kmph;
    
  int SizeOfArray = sizeof(bA) / sizeof(bA[0]);
  bA[4] = checkSum(bA, SizeOfArray);  //Calculate and add the checksum to byte array
  
  for(int i = 0; i < SizeOfArray; i++)
  {
    //Write bytes serially to pin 3. This should be connected to the GREY wire of the Jetson Bolt Pro
    mySerial.write(bA[i]);
  }

}

byte checkSum(byte byteArray[], int arraySize)
{
  byte checksum = 0x00;
  for(int i = 0; i < arraySize - 2; i++)
    checksum ^= byteArray[i];
  return checksum;
}

void loop()
{
  up_var = !digitalRead(up);
  Horn_var = !digitalRead(Horn_b);
  down_var = !digitalRead(down);
  RTurn_var = !digitalRead(RTurn);
  LTurn_var = !digitalRead(LTurn);
  Brakes_var = digitalRead(Brakes);
  unsigned long currentMillis = millis();
  
//read
  if (mySerial.available())
  {
      incoming = mySerial.read();
      if (incoming != 0xBB)
      {
        incomingArr[index] = incoming;
        index++;
      } 
      else 
      {
        
        if (checkSum(incomingArr, 10) == incomingArr[8])
        {
          if (incomingArr[1] == 0xA1)
          {
            speedRPM = (incomingArr[5-1] * 0xff) + incomingArr[6-1];
            temperature = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA2)
          {
            odo = incomingArr[5-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA3)
          {
            maxSpeedKM = incomingArr[4-1];
            runTime = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA4)
          {
            headlight = incomingArr[8-1];
            printRegister(incomingArr);
          }
          else if (incomingArr[1] == 0xA7)
          {
            printRegister(incomingArr);
          }
        }
        
        index = 0;
      }
  }
//read
  
//Hb
  if (Horn_var == 0 && currentMillis - HbpreviousMillis < 1500 && currentMillis - HbpreviousMillis > 120)
  {
    HTog = !HTog;
  }
  if (Horn_var == 0 && currentMillis - HbpreviousMillis >= 1500)
  {
    sel = !sel;
  }
  if (Horn_var == 0)
  {
    HbpreviousMillis = currentMillis;
  }
//Hb

  if (RTurn_var == 1 && LTurn_var == 0)
  {
    RTog = !RTog;
    LTog = 0;
    delay(250);
  }
  if (LTurn_var == 1 && RTurn_var == 0)
  {
    LTog = !LTog;
    RTog = 0;
    delay(250);
  }
  if (Brakes_var == 1)
  {
    analogWrite(Brakes_LED,255);
  }
  else
  {
    analogWrite(Brakes_LED,70);
  }

  if (HTog == 1 && currentMillis - HpreviousMillis >= 300)
  {
    digitalWrite(Horn,HIGH);
    delay(10);
    digitalWrite(Horn,LOW);
    HpreviousMillis = currentMillis;
  }
  
  if (RTog == 1 && currentMillis - RpreviousMillis >= interval && RState == 0)
  {
    digitalWrite(RLED,HIGH);
    RState = 1;
    LState = 0;
    yel = "---------->";
    RpreviousMillis = currentMillis;
  }
  else if (RTog == 1 && currentMillis - RpreviousMillis >= interval && RState == 1)
  {
    digitalWrite(RLED,LOW);
    RState = 0;
    LState = 0;
    RpreviousMillis = currentMillis;
  }
  
  if (LTog == 1 && currentMillis - LpreviousMillis >= interval && LState == 0)
  {
    digitalWrite(LLED,HIGH);
    LState = 1;
    RState = 0;
    yel = "<----------";
    LpreviousMillis = currentMillis;
  }
  else if (LTog == 1 && currentMillis - LpreviousMillis >= interval  && LState == 1)
  {
    digitalWrite(LLED,LOW);
    LState = 0;
    RState = 0;
    LpreviousMillis = currentMillis;
  }
  
  if (LTog == 0 && RTog == 0)
  {
    digitalWrite(LLED,LOW);
    digitalWrite(RLED,LOW);
    LState = 0;
    RState = 0;
    yel = "-----------";
  }
  
//menu
  if (sel == 0)
  {
    blu1 = String(" MAX:" + String(TMPH) + "----");
    blu2 = String(">" + String(speed,1) + "-" + String(speed_,1));
    blu3 = String(">" + String(temperature) + "C-" + String(temperature_) + "C");
    if (up_var == 1 && up_var + down_var == 1)
    {
      speed_ = speed;
    }
    if (down_var == 1 && up_var + down_var == 1)
    {
      temperature_ = temperature;
    }
  }
  if (sel == 1)
  {
    blu1 = String(">MAX:" + String(TMPH) + "----");
    blu2 = String(" " + String(speed,1) + "-" + String(speed_,1));
    blu3 = String(" " + String(temperature) + "C-" + String(temperature_) + "C");
    
    if (up_var == 1 && up_var + down_var == 1 && TMPH < 19)
    {
      TMPH = TMPH + 1;
      kmph = (TMPH) * 1.609;
      delay(500);
    }
    if (down_var == 1 && up_var + down_var == 1 && TMPH > 11)
    {
      TMPH = TMPH - 1;
      kmph = (TMPH) * 1.609;
      delay(500);
    }
  }
//menu
  
  if (temperature >= Tmax && TMPH > 15)
  {
    TMPH = 15;
    kmph = (TMPH) * 1.609;
    up_var = 0;
    down_var = 1;
  }


  if (up_var + down_var == 1)
  {
     bA[3] = kmph;
    
    int SizeOfArray = sizeof(bA) / sizeof(bA[0]);
    bA[4] = checkSum(bA, SizeOfArray);  //Calculate and add the checksum to byte array
  
    for(int i = 0; i < SizeOfArray; i++)
    {
      //Write bytes serially to pin 3. This should be connected to the GREY wire of the Jetson Bolt Pro
      mySerial.write(bA[i]);
    }
  }
  
  if (currentMillis - oledpreviousMillis >= 500)
  {
    oled.clear();
    oled.println(yel);
    oled.println(blu1);
    oled.println(blu2);
    oled.println(blu3);
    oledpreviousMillis = currentMillis;
  }
}

have a look at how-to-get-the-best-out-of-this-forum
give details of the attached devices?
upload a schematic of the wiring?

digitalRead should normally return HIGH because of the pullup, but your logic inverts it so "Horn_var" is normally "0" when the button is not pressed

with Horn_var "0", all of the conditions below are eventually true

That specific section of code is so Hbprevious matches currentMillis until the button is pressed. It then keeps track of how long the button has been pressed and does the appropriate action, based on the press length, only when the button is released. I do not see how if statement 1 or 2 would trigger if the horn button never gets pressed since Hbprevious should still be within 120ms of currentMillis, even with the time it takes for the arduino to work taken into account.

Does anyone have a better way of counting button press length?

Please elaborate :thinking: .

so you're waiting for the button to be released to determine if it has been pressed long enough

another approach is to capture the timestamp when it is pressed

    if (1 == Horn_var)
        msecLst = millis();

and then either recognize that it has been pressed long enough because the time has expired

    if (1 == Horn_var && millis - msecLst >= 1500)  {
        // pressed long enough
    }

or released before the time expires

1 Like

This seems like a good solution for one command, but I can't figure out how to rewrite it for two or more exclusively selected (xor) commands based on hold duration.

do you just mean more than one button or do you mean multiple buttons simultaneously pressed for some period of time?

Placing a 100R resistor in series with GND will bite you in the butt, do not do this.

Each LED needs a series dropping resistance, 220R should suffice.

You know how some video games have a function for tapping a button and a completely unrelated function for holding that exact same button without activating the tap function? I'm trying to figure out how to do that without the code doing something weird.

How long is a "tap"?

In an ideal piece of code, it's whatever the user/coder wants it to be. For the sake of an example, let's say 120ms - 300ms. Anything longer would be a "hold" and therefore a different output/function. Anything shorter could be a loose connection or a button bouncing the input and ignored.

This is true, but I made the digital schematic reflect what I had irl.

Your LEDs should be connected as D1 or D2.

Do not add the GND resistor in your schematic.

All of this is really constructive, but it still doesn't tell me why menu up/down (simply labeled as up/down in the code) starts or stops the horn's beeping function, which doesn't even mention up or down. I even gave the beeping function a minimum time to allow for any delay() or time added from running the code.

If you expect reasonable responses you should add meaningful comments to the code so we don’t have to figure out your algorithm (which is not working).

If you won’t do it for the volunteers do it for yourself.

Attach a bare minimum sketch that still reflects the problem.

Place print statements at strategic locations to prove variables are what you think they are when actions occur.

Good point, doing that right now.

i think you would need to recognize a change in button status, this means any combination of buttons, and capture a timestamp for the last state.

you can then wait for some minimum time (~100msec) to expire to recognize that state or even longer (~1sec). if the button state changes before the longer time expires, recognize a short button press event and recognize the longer period event when the timer expires