débutant comprend pas code
#1
Posté 19 février 2012 - 06:46
je ne comprend pas pourquoi avec ces lignes de codes quand j'appuie sur un bouton la led reste allumée et quand j'appuie sur l'autre la led reste éteinte ?
J'aurais pensé qu'il referait à chaque fois la vérification et que ça marcherait plutôt comme un bouton poussoir...
Si quelqu'un peu m'éclairer merci beaucoup !!!
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13;
const int buttonPin2 = 3;// the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode (buttonPin2, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (digitalRead(buttonPin) ==LOW) { // si l'interrupteur 1 est fermé
// turn LED on:
digitalWrite(ledPin, LOW); } // la led est éteinte
else if (digitalRead(buttonPin2)==LOW) {
digitalWrite (ledPin, HIGH );
}
}
#2
Posté 19 février 2012 - 07:12
Essai avec des bouton poussoir instantané.
Page Facebook : https://www.facebook...appartelier2.0/
Page Twitter : https://twitter.com/2Appartelier (bateau seulement)
Boutique Robot-Maker : https://www.robot-ma...er-20/produits/
Besoin d'une impression 3D grand format ? Contactez moi !
#3
Posté 19 février 2012 - 07:29
En fait tu demande que lorsque ton bouton est appuyé, la Led passe a HIGH
Elle le retera tant que tu n'aura pas donné l'ordes qu'elle passe LOW
Donc comme un bouton marche arret tu dois :
Quand tu presse le nouton 1 ta LED PAsse HUGH
Dand tu presse sur le bouton 2 ta LED passe a LOW
Cdlt
Yves
#4
Posté 19 février 2012 - 11:13
donc si j'ai bien compris la différence entre l'autre code et celui-ci c'est que dans celui-ci j'ai le else qui implique le fait que dès que le bouton poussoir un relaché la led change d'état ?
// constants won’t change. They’re used here to
// set pin numbers:
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);
}
}
#5
Posté 19 février 2012 - 11:32
Page Facebook : https://www.facebook...appartelier2.0/
Page Twitter : https://twitter.com/2Appartelier (bateau seulement)
Boutique Robot-Maker : https://www.robot-ma...er-20/produits/
Besoin d'une impression 3D grand format ? Contactez moi !
0 utilisateur(s) li(sen)t ce sujet
0 members, 0 guests, 0 anonymous users