F-16 flight simulator

I am working on a f-16 for a school project. i need to use a normal button but im not sure how. also i need to push it up into the on position and the arduino only send a serial signal once instead of over and over agian while the button is pressed. i would love some help if at all possible

One common way to deal with a pushbutton is to wire the pushbutton between an Arduino input pin and ground, set up the input pin to have an INPUT_PULL UP, and then use the digitalRead(...) function. LOW means that the pushbutton is pressed, and HIGH means that the pushbutton is not pressed.

There is a State Change example in the IDE to see when a switch goes from off to on. Use it.

A problem with switches is that the contacts bounce. Look for ways to debounce. The Bounce2 library may be helpful.

vaj4088:
A problem with switches is that the contacts bounce. Look for ways to debounce. The Bounce2 library may be helpful.

Could you please explain this a little more as i dont quite understand it

Please explain your project with more details, When the Arduino continuously sends data while a button is pressed, where does it send the data?

Do you want to use the Arduino for input to a simulation program?

it will send a number through serial to the computer. then i wrote a program that can read that and emulates a key press and that has a function in the game. i have switches on the simulator that will allow for things like weapons and fuel flow so it will do what the switch in the game does

So you want to create a remote console for the game.

See the StateChangeDetection example, and send buttonUp and buttonDown messages when a change is detected. Or use the AButton class for easy button handling.

okay thankyou for your assistants

Droneo wrote (in part, writing about debouncing):

Could you please explain this a little more as i dont quite understand it

The Arduino article on debouncing is at https://www.arduino.cc/en/Tutorial/Debounce

The article references the Limor Fried code which is located at http://energia.nu/guide/tutorial_debounce/

You do not need the 10K pullup resistor or the connection to Vcc because you are using the INPUT_PULLUP mode.

const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}

void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;

// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

I tried this but it didnt work

"It didn't work" is not useful information. What did you expect, what actually happened, how did you have things wired, what did the serial prints show?