Bonjour,

en tant que novice je planche sur une porte de poulailler (j'ai l'impression c'est un sujet fréquent) et j'ai repris, changé un code trouvé.

Il marche très bien en mode détection jour avec la Dusk2Dawn library et la porte s'ouvre et ferme suivant l'état du jour ainsi indiqué.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
if ((sunrise + 5 < currentMins && currentMins < sunset + 35))
  {
    Serial.println("Door should be up");
    while ( digitalRead(doorUpSensorPin) == LOW )
    raiseDoor();
    }
 
  else
  {
    Serial.println("Door should be down");
    while ( digitalRead(doorDownSensorPin) == LOW )
    lowerDoor();
   }
Ce que je voudrais ajouter est un bouton qui permettrait d'aller en mode manuel.

En somme j'ai imaginé ca comme une fonction si le bouton manual mode est sur on alors utiliser la fonction mode manuel sinon utiliser la fonction mode Jour/nuit automatique ou le code qui marche ci dessus est dans le "SunTimeMode" de la formule après:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 if (ManualModeSwitch = HIGH)
  {
    Serial.println("Manual mode ON");
    ManualMode();
    }
 
  else
  {
    Serial.println("Manual mode OFF");
    SunTimeMode();
   }
Sauf que ca ne marche pas et je sais pas pourquoi. L'IDE me dit "'SunTimeMode' cannot be used as a function".

Evidement je suis débutant alors peut etre c'est juste une ";" ce que j'espere pas.

Est-ce qu'un.e voudrait bien m'aider ? Ca serait chouette pour moi de comprendre pourquoi ca ne marche pas
Sinon je vais sans doute laisser la version simple sans mode manuel...

merci bien !

Le code (déféctueux) entier est celui ci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include <math.h>
#include <Dusk2Dawn.h>
#include <EEPROM.h>
#include <Wire.h>
#include "RTClib.h"
 
 
 
//Define what pins are used
const int doorUpSensorPin = 4;        // reedswitch door open
const int doorDownSensorPin = 5;      // reedswitch door down
const int doorDownMotorPin = 10;      // wind motor down
const int DoorUpMotorPin = 9;         // wind motor up
const int closedLED = 12;            // LED idicating door closed (reedswitch on pin 5)
const int openLED = 11;            // LED idicating door open (reedswitch on pin 4)
const byte ManualModeSwitch = 2;       // Open door by hand
const byte CloseDoorManual = 3;       // Close door by hand
const byte OpenDoorManual = 6;       // Open door by hand
 
int buttonstateclose = 0;
int buttonstateopen = 0;
int manualmodeon = 0;
int SunTimeMode = 0;
int currentMins;
int sunrise;
int sunset;
DateTime now;
 
//Are We Debugging?
const bool debug = true;
//Do we need to set/adjust RTC?
const bool setRTC = false;
 
//Define RTC
RTC_DS3231 rtc;
 
//define the location / timezone for dusk2dawn (this is yourcity, countrycode 2 digit)
// change yourcity an fill in coordinates and timezone
Dusk2Dawn ClermontFerrand(45.766506, 3.118097, 0); 
 
 
// the setup function runs once when you press reset or power the board
void setup() {
 
  //Set the mode the pins will operate in.
    pinMode(DoorUpMotorPin, OUTPUT);
    pinMode(doorDownMotorPin, OUTPUT);
    pinMode(CloseDoorManual, INPUT);
    pinMode(OpenDoorManual, INPUT); 
 
 
  //Set Serial for Debugging
  if (debug) {
    Serial.begin(9600);
 
    if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
    }
 
  rtc.begin();
  //   //Lets just set the date/time when setRTC = true.
  if (setRTC)
  {
   //write PC date and time while uploading and when setRTC = true
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 
   //uncomment line 71 to write date and time manually into RTC when line 38 setRTC = true. For testing sunset/sunrise
    //rtc.adjust(DateTime(2020, 7, 23, 7, 9, 20));       
  }
 }
 
 
 
  //switches setup
  pinMode(doorUpSensorPin, INPUT);
  pinMode(doorDownSensorPin, INPUT);
  pinMode(closedLED, OUTPUT);
  pinMode(openLED, OUTPUT);
  pinMode (ManualModeSwitch, INPUT);
 
  Serial.println("FinishedSetup");
  if (digitalRead(doorUpSensorPin) == HIGH) 
  {
   Serial.println("Door is open");
   }
 
   if (digitalRead(doorDownSensorPin) == HIGH)
   {
    Serial.println("Door is closed");
   }
   delay(3000);
}
 
 
// the loop function runs over and over again until power down or reset
void loop() {
  delay(2000);
  if (debug){
    Serial.println();
    Serial.println("LoopHead");
  }
  //Get the Date/Time from the RTC
  now = rtc.now();
  //Get Sunrise/Sunset for the current year/month/day as INT's that equate to minutes from midnight that he sunrise/sunset will occur (THE TRUE is passing in Daylight Savings Time!)
  int sunrise = ClermontFerrand.sunrise(now.year(), now.month(), now.day(), true);
  int sunset = ClermontFerrand.sunset(now.year(), now.month(), now.day(), true);
  if (debug) {
    Serial.println();
    Serial.print(now.year());
    Serial.print('/');
    Serial.print(now.month());
    Serial.print('/');
    Serial.print(now.day());
    Serial.print(" - ");
    Serial.print(now.hour());
    Serial.print(':');
    Serial.print(now.minute());
    Serial.print(':');
    Serial.print(now.second());
    Serial.print(" - ");
  char time2[] = "00:00";
    Dusk2Dawn::min2str(time2, sunrise);
    Serial.println("Sunrise");
    Serial.println(time2);
    Dusk2Dawn::min2str(time2, sunset);
    Serial.println("Sunset");
    Serial.println(time2);
 
 
  }   
 
 
    /*buttonstateclose = digitalRead(CloseDoorManual);
    if(buttonstateclose == HIGH) ;{
      ManualClose();}
    
    buttonstateopen = digitalRead(OpenDoorManual);
    if(buttonstateopen == HIGH);{
      ManualOpen();
    }*/
 
 
 
  //Lets get add the "now" Minutes and "now" hours*60 to see how many minutes from midnight we are
  currentMins = ((now.hour()) * 60) + (now.minute());
  Serial.println(currentMins);
 
    if (ManualModeSwitch = HIGH)
  {
    Serial.println("Manual mode ON");
    ManualMode();
    }
 
  else
  {
    Serial.println("Manual mode OFF");
    SunTimeMode();
   }
 
 
 
 
 
 
 
  int DoorUp = digitalRead(doorUpSensorPin);
  int DoorDown = digitalRead(doorDownSensorPin);
  /* This is just temporary switch debug code*/
  if (DoorUp == HIGH)
  {
    Serial.println("Door Opened All The Way");
    digitalWrite(closedLED, LOW);
    digitalWrite(openLED, HIGH);
    stopDoor();
    /*delay(1000);
    digitalWrite(closedLED, LOW);
    digitalWrite(openLED, LOW);*/
  }
 
  else
  {
    digitalRead(doorDownSensorPin == HIGH);
    Serial.println("Door Closed All The Way");
    digitalWrite(closedLED, HIGH);
    digitalWrite(openLED, LOW);
    stopDoor();
   /* delay(1000);
    digitalWrite(closedLED, LOW);
    digitalWrite(openLED, LOW);*/
  } 
}
 
 
 
//Wind the Door Up
void raiseDoor() {
  digitalWrite(DoorUpMotorPin, HIGH);
  digitalWrite(doorDownMotorPin, LOW);
  if (debug) {
    Serial.println("Door Raising");
  }
}
 
 
//Wind The Door Down
void lowerDoor() {
  digitalWrite(doorDownMotorPin, HIGH);
  digitalWrite(DoorUpMotorPin, LOW);
  if (debug) {
    Serial.println("Door Lowering");
  }
}
 
 
//Stop the Door
void stopDoor() {
  digitalWrite(DoorUpMotorPin, LOW);
  digitalWrite(doorDownMotorPin, LOW);
  if (debug) {
    Serial.println("Door Stop");
  }
}
 
 
//Manual Mode switch
void ManualMode() {
 if (CloseDoorManual == HIGH)
   {lowerDoor();
    stopDoor();
   }
 
else
  {
    raiseDoor();
    stopDoor();
  } 
 
 
 
void SunTimeMode() {
//lets start comparisons, if the door should be up....
  //delay of 30 minutes after sunset time to make sure all chickens are inside before closing the door. 
  if ((sunrise + 5 < currentMins && currentMins < sunset + 35) && ( buttonstateclose != HIGH) )
  {
    Serial.println("Door should be up");
    while ( digitalRead(doorUpSensorPin) == LOW )
    raiseDoor();
    }
 
  else
  {
    Serial.println("Door should be down");
    while ( digitalRead(doorDownSensorPin) == LOW )
    lowerDoor();
   }
 
 
 
 
//Close door manual
void ManualClose() { 
  digitalWrite(doorDownMotorPin, HIGH);
  digitalWrite(DoorUpMotorPin, LOW);
  if (debug) {
    Serial.println("Door Closing Manual");
  while ( digitalRead(doorDownSensorPin) == LOW)
   digitalWrite(closedLED, HIGH);
   digitalWrite(openLED, LOW);
    stopDoor();
    /*delay(1000);
    digitalWrite(closedLED, LOW);
    digitalWrite(openLED, LOW);*/
  }
 }
 //Open door manual
void ManualOpen() { 
  digitalWrite(doorDownMotorPin, LOW);
  digitalWrite(DoorUpMotorPin, HIGH);
  if (debug) {
    Serial.println("Door Opening Manual");
  while ( digitalRead(doorUpSensorPin) == LOW)
    digitalWrite(closedLED, LOW);
     digitalWrite(openLED, HIGH);
    stopDoor();
    /*delay(1000);
    digitalWrite(closedLED, LOW);
    digitalWrite(openLED, LOW);*/
  }
 }