bonjour je suis novice en programmation arduino et j'ai un soucis avec mon programme, la compilation se fait bien mais le servo ne fonctionne pas normalement il donne une impulsion à chaque seconde et ne fait pas son cycle qui devrait etre de 0 à 180 degrés .
si quelqu'un pouvait jetter un oeil
merci d'avance.
#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>
RTC_DS1307 RTC;
const int relais=7;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo myservo; // create servo object to control a servo
int pos = 90; // variable to store the servo position
void setup() {
Wire.begin();
RTC.begin();
lcd.begin(20, 2);
pinMode (relais, OUTPUT);
myservo.attach(8); // attaches the servo on pin 8 to the servo object
}
void loop() {
//digitalWrite (relay,HIGH);
//digitalWrite (relay,LOW);
DateTime now = RTC.now();
// l'heure sur la premiêre ligne du LCD
lcd.setCursor(0, 0);
lcd.print(now.hour());
lcd.print(":");
if (now.minute() < 10) {
lcd.print("0");
}
lcd.print(now.minute());
lcd.print(":");
if (now.second() < 10) {
lcd.print("0");
}
lcd.print(now.second());
// la date sur la deuxième partie de la ligne1 du LCD
lcd.setCursor(10, 0);
lcd.print(now.day());
lcd.print("/");
switch (now.month()) {
case 1:
lcd.print("01");
break;
case 2:
lcd.print("02");
break;
case 3:
lcd.print("03");
break;
case 4:
lcd.print("04");
break;
case 5:
lcd.print("05");
break;
case 6:
lcd.print("06");
break;
case 7:
lcd.print("07");
break;
case 8:
lcd.print("08");
break;
case 9:
lcd.print("09");
break;
case 10:
lcd.print("10");
break;
case 11:
lcd.print("11");
break;
case 12:
lcd.print("12");
break;
}
lcd.print("/");
lcd.print(now.year());
delay(1000);
lcd.clear();
{
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(15); // waits 15ms 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(15); // waits 15ms for the servo to reach the position
}
if (now.hour() == 16 && now.minute() ==15) {
digitalWrite (relais,HIGH);
lcd.setCursor(0,1);
lcd.print("OSCILLO OFF");
}
if (now.hour() == 16 && now.minute() == 16){
digitalWrite (relais,LOW);
lcd.setCursor(0,1);
lcd.print("OSCILLO ON");
}
if (now.hour() == 16 && now.minute() == 17) {
digitalWrite (relais,HIGH);
lcd.setCursor(0,1);
lcd.print("OSCILLO OFF");
}
if (now.hour() == 16 && now.minute() == 18){
digitalWrite (relais,LOW);
lcd.setCursor(0,1);
lcd.print("OSCILLO ON");
}
}