Après avoir rapidement cherché sur le forum une solution, mon problème persiste..
Je cherche à intégrer une boucle dans la fonction void loop, mon programme est pourtant excessivement simple mais je n'y parviens pas.
Je voudrais que les instructions données au servo se répètent en boucle tandis que les 4 Leds s'allument chacune leur tour pendant 10 secondes.
J'ai essayé de mettre le programme concernant le servo dans une boucle while(1) mais cela empêchait évidemment les instructions données aux Leds de s'activer.
Me voilà bêtement bloqué..
Voici mon code :
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
pinMode(5, OUTPUT); // 1st LED
pinMode(4, OUTPUT); // 2nd LED
pinMode(3, OUTPUT); // 3rd LED
pinMode(2, OUTPUT); // 4th LED
myservo.attach(7); // assigne le servo à la sortie 7
}
void loop()
{
digitalWrite(5,HIGH); // toutes les LEDs sont éteintes
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
digitalWrite(5, LOW); // turn the 1st LED on
delay(10000); // wait for 10 second
digitalWrite(5,HIGH); // turn the 1st LED off
digitalWrite(4, LOW); // turn the 2nd LED on
delay(10000); // wait for 10 second
digitalWrite(4,HIGH); // turn the 2nd LED off
digitalWrite(3,LOW); // turn the 3rd LED on
delay(10000); // wait for 10 second
digitalWrite(3,HIGH); // turn the 3rd LED off
digitalWrite(2, LOW); // turn the 4th LED on
delay(10000); // wait for 10 second
digitalWrite(2,HIGH); // turn the 4th LED off
for(pos = 0; pos <= 180; pos += 1)// goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25);
}
}
Merci de votre aide !