Vidéo de démonstration :
Schéma de câblage :
Code :
const int in1Pin = 9; //Broche de commandein1 L298N
const int in2Pin = 8; //Broche de commande in2 L298N
const int BtBleue = 4; //Pin du bouton Bleue
const int BtVert = 3; //Pin du bouton Vert
bool EtatBtBleue;
bool EtatBtVert;
void setup() {
Serial.begin(9600);
//Déclaration des entrées-sorties
pinMode(BtBleue, INPUT_PULLUP);
pinMode(BtVert, INPUT_PULLUP);
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
}
void loop() {
//Lecture des Boutons
EtatBtBleue = digitalRead(BtBleue);
EtatBtVert = digitalRead(BtVert);
//Si BtBleue : sortie vérin, sinon si BtVert : rentré vérin sinon repos
if (EtatBtBleue == LOW) {
Serial.println("bl");
digitalWrite(in1Pin, HIGH);
digitalWrite(in2Pin, LOW);
} else if (EtatBtVert == LOW) {
Serial.println("bV");
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, HIGH);
} else {
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, LOW);
}
}
Post Views: 91
J’aime ça :
J’aime chargement…