Realizar una acción si se pulsa un botón

Buenas,
Estoy pasando un programa hecho en C (era para un pic) a Arduino.
No sé como realitzar una acción cuando ha sido pulsado un botón.
En el codigo para el pic es: if(input(pulsador_ok) {
accion }
¿Como podria substituir este input con lenguaje Arduino? Hay alguna forma o función de detectar si se pulsa un botón?

Muchas gracias.

En el programa de Arduino en la pestaña Archivo---> Ejemplos---> 0.2 Digital---> Button tienes este codigo:

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Tienes un boton conectado al pin digital 2, int buttonstate = 0 sirve para guardar el valor que lea arduino en el pin del boton

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }

Esta parte lo que hace es leer buttonState o el pin 2 y dependiendo de si esta pulsado o no enciende un led o lo apaga respectivamente.

Espero no equivocarme. :slight_smile: