Bonjour à tous, je travail sur un projet utilisant la plateforme Arduino et j'ai quelques difficultés à obtenir ce que je souhaite.
Le but du projet est d'injecter de l'hydrogène dans un moteur ayant huit cylindre. C'est l'Arduino qui s'occupe de déclencher le injecteurs au moment souhaité.
Pour ce faire, j'utilise un disque ayant 8 trous et un capteur lumineux relié à l'Arduino. Lorsque le moteur fonctionne, le disque tourne. Lorsque le capteur lumineux rencontre un trou, la tension de sortie du capteur est nulle. De plus, l'Arduino doit déclencher un des injecteurs. Il y a un ordre de déclenchement des injecteurs à respecter : 1, 8, 7, 5, 4, 3, 6, 2.
Ci-dessous l’algorithme que j'ai rédigé:
int lightsensor = 0; //variable used to store the value from the lightsensor.
int timeINJ = 1; // variable used to store the time value of working of the injector.
void setup() {
// Initialization of all the injectors as output:
pinMode(0, OUTPUT); //INJ1 is as an OUTPUT
pinMode(1, OUTPUT); //INJ2 is as an OUTPUT
pinMode(2, OUTPUT); //INJ3 is as an OUTPUT
pinMode(3, OUTPUT); //INJ4 is as an OUTPUT
pinMode(4, OUTPUT); //INJ5 is as an OUTPUT
pinMode(5, OUTPUT); //INJ6 is as an OUTPUT
pinMode(6, OUTPUT); //INJ7 is as an OUTPUT
pinMode(7, OUTPUT); //INJ8 is as an OUTPUT
// All the injectors are off at the begining:
digitalWrite(0, LOW); //Set injector 1's pin LOW
digitalWrite(1, LOW); //Set injector 2's pin LOW
digitalWrite(2, LOW); //Set injector 3's pin LOW
digitalWrite(3, LOW); //Set injector 4's pin LOW
digitalWrite(4, LOW); //Set injector 5's pin LOW
digitalWrite(5, LOW); //Set injector 6's pin LOW
digitalWrite(6, LOW); //Set injector 7's pin LOW
digitalWrite(7, LOW); //Set injector 8's pin LOW
}
void loop() {
// Working stage : The algorithm injects hydrogen in each cylinder when it is the appropiate moment. For each hole, one of the cylinder will recieve hydrogen:
while (1){ //as we just want to use the piezosensor one time, we use while(1). Like 1 is not a variable, it will never change.
//The condition will never become false. The loop will be repeat forever.
// Wait to meet a hole:
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){ //if the controller meet a hole
digitalWrite(0,HIGH); //start the hydrogen injection in the cylinder 1
delay(timeINJ); //during 1 ms
digitalWrite(0,LOW); //stop the hydrogen injection in the cylinder 5
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(7,HIGH);
delay(timeINJ);
digitalWrite(7,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(6,HIGH);
delay(timeINJ);
digitalWrite(6,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(4,HIGH);
delay(timeINJ);
digitalWrite(4,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(3,HIGH);
delay(timeINJ);
digitalWrite(3,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(2,HIGH);
delay(timeINJ);
digitalWrite(2,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(5,HIGH);
delay(timeINJ);
digitalWrite(5,LOW);
}
lightsensor = analogRead(A0);
while (lightsensor != 0){
lightsensor = analogRead(A0);
}
if (lightsensor = 0){
digitalWrite(1,HIGH);
delay(timeINJ);
digitalWrite(1,LOW);
}
// Repeat the working stage forever until the engine is stoped.
}
}
Cet algorithme va être développe et sera beaucoup plus long. Afin de le rendre plus clair, j'aimerai renommer mes sorties digitales. Par exemple, l'injecteur 1 est branché sur la sortie 0, j'aimerai pouvoir nommer cette sortie "INJ1". Ainsi, je n'écrirai plus :
pinMode(0, OUTPUT); //INJ1 is as an OUTPUT
mais
pinMode(INJ1, OUTPUT); //INJ1 is as an OUTPUT.
Pensez-vous que ce genre de manipulation soit possible?
N'hésitez pas à me poser des questions si mon message n'est pas assez clair
Merci d'avance!!