Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | |||
projets:coop:start [2021/01/14 17:08] enseignant [Notes techniques et matériaux] |
projets:coop:start [2021/01/14 17:14] (Version actuelle) enseignant [Code simple pour arduino un bouton active un relai] |
||
---|---|---|---|
Ligne 24: | Ligne 24: | ||
<code c+> | <code c+> | ||
- | const int buttonPin = 2; // | + | const int buttonPin = 2; // |
- | const int relai = 4; // the number of the LED pin | + | const int relai = 4; // relay pin |
- | + | int buttonState = 0; // variable | |
- | // variables will change: | + | |
- | int buttonState = 0; // variable | + | |
void setup() { | void setup() { | ||
- | // initialize the LED pin as an output: | ||
pinMode(relai, | pinMode(relai, | ||
- | // initialize the pushbutton pin as an input: | ||
pinMode(buttonPin, | pinMode(buttonPin, | ||
} | } | ||
Ligne 41: | Ligne 37: | ||
buttonState = digitalRead(buttonPin); | buttonState = digitalRead(buttonPin); | ||
- | // check if the pushbutton is pressed. If it is, the buttonState is HIGH: | ||
if (buttonState == HIGH) { | if (buttonState == HIGH) { | ||
- | // turn LED on: | ||
digitalWrite(relai, | digitalWrite(relai, | ||
} else { | } else { | ||
- | // turn LED off: | ||
digitalWrite(relai, | digitalWrite(relai, | ||
} | } |