Button question.

I am wanting to add to a program I made for our SEMA display last year for this years SEMA display. What I want to do is have a program that runs when I hit a momentary push button. And another if I hit a second button. Below is a copy of the program I wrote for last years display. This year we are adding another fan to control and we want it to run slightly different.

I had to shorten this sample in order to come in under 9500 characters.

#include "Wire.h"
#include "LiquidCrystal.h"
#include "Servo.h"

Servo myservo;

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);

void setup() {
  myservo.attach(9);
  lcd.begin(20, 4.);
  lcd.setBacklight(HIGH);
  lcd.print(" Derale Performance");
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(90);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(90);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(90);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  12.0   8    160");
  myservo.write(110);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  13.2  5.0   160");
  myservo.write(113);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  14.5  7.5   160");
  myservo.write(116);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  15.4   10   160");
  myservo.write(119);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  16.6  12.5   160");
  myservo.write(121);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  17.3  15   160");
  myservo.write(124);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  18.8  17.5   160");
  myservo.write(127);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  19.3   20   160");
  myservo.write(130);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  20.2  22.5   160");
  myservo.write(133);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  21.5  25   160");
  myservo.write(136);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  22.8  27.5   160");
  myservo.write(139);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  23.6  30   160");
  myservo.write(141);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  24.2  32.5   160");
  myservo.write(144);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  25.3   35   160");
  myservo.write(147);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  26.4   37.5   160");
  myservo.write(150);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  27.3   40   160");
  myservo.write(153);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  28.6  42.5   160");
  myservo.write(156);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  29.7  45   160");
  myservo.write(159);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  32.3  47.5   160");
  myservo.write(162);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  35.8  50   160");
  myservo.write(165);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  36.2  52.5   160");
  myservo.write(168);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  37.3  55.0   160");
  myservo.write(171);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  39.4  57.5   160");
  myservo.write(174);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  41.2  60.0   160");
  myservo.write(177);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  43.8  62.5   160");
  myservo.write(180);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  65.0   160");
  myservo.write(177);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  67.5   160");
  myservo.write(174);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  70.0   160");
  myservo.write(171);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  72.5   160");
  myservo.write(168);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  75.0   160");
  myservo.write(165);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  77.5   160");
  myservo.write(162);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  80.0   160");
  myservo.write(159);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  82.5   160");
  myservo.write(156);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0  85.0   160");
  myservo.write(159);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(108);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(105);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(102);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(99);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(96);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(93);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(90);
  delay(2500);
  lcd.setCursor(0,2);
  lcd.print("  Amps  Fan%  Temp");
  lcd.setCursor(0,3);
  lcd.print("  00.0    0   160");
  myservo.write(90);
  delay(2500);
  
}
  
  void loop() {
  
}

What I want to do is have a program that runs when I hit a momentary push button. And another if I hit a second button.

So, what's the problem?

Connect the switch to ground and to a digital pin. In setup(), add a pinMode() call, with the pin number and INPUT_PULLUP. Then, use digitalRead() on the pin. LOW means pressed. HIGH means not pressed.

Of course, having everything in setup() means that you'll need to be pressing the switch when the Arduino starts...

You can use the Additional Options... link (in orange below this window) to attach code that is more than 9500 characters.

Thanks for your reply, My problem is I am new to this and not really sure how this task is accomplished or how to program it.

My problem is I am new to this and not really sure how this task is accomplished or how to program it.

So, you try something. It either works, or it doesn't. If it does, you study what you did, and make sure you understand why it worked. If it didn't, you study the code, and try to understand why it didn't work. If you can't understand that, you post the code, a picture of the setup, and an explanation of what actually happens.

The typical picture, way too large, out of focus, poorly lit, with all black wires jumbled up, doesn't cut it.

If this part doesn't change then why do you want it to constantly be written on the screen?

lcd.setCursor(0,2);
lcd.print(" Amps Fan% Temp");
lcd.setCursor(0,3);

Just change the values and take out the delays.

For a simple approach to your problem, you can prompt the user to press X for loop_A or press Y for loop_B (just an example). Once the user has made a choice, the code runs that loop all while checking to see if the other choice is ever selected. If the other choice is selected, the code then breaks from the first choice to then run the other loop.