Problema con ejemplo de botón
Publicado por Sebastián (1 intervención) el 24/04/2021 21:59:57
Estimados, soy nuevo en Arduino y estoy practicando con los primeros ejemplos, mi problema es el siguiente: Hago la instalación y coloco el código del ejemplo, mirando incluso el libro de ejemplos, pero al cargar el código lo que hace es mantener encendido el led del pin 13, he estado viendo que podría ser y me di cuenta que el pin 13 se enciende con simplemente colocar un cable en el pin 2, es decir, tan solo con colocar un cable suelto en el pin 2 (que es el pin que debe ir al botón) hace que encienda la luz, lo que me parece muy extraño. Intenté colocando leds en otros pines y nada, tengo un botón de 4 patillas, no se si ese será el problema. No si se habrá algún problema con mi placa o con el botón, pero al menos en otros ejemplos no he tenido ningún problema.
Adjunto el código que uso:
Saludos

Adjunto el código que uso:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
}
}
Saludos
Valora esta pregunta


0