first commit
This commit is contained in:
248
SOLAIRE_TRACKER/Date_heure.cpp
Normal file
248
SOLAIRE_TRACKER/Date_heure.cpp
Normal file
@@ -0,0 +1,248 @@
|
||||
|
||||
|
||||
#include "Date_heure.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
//tableau de char pour la gestion des jour par mois
|
||||
int jParM[12]={31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
|
||||
|
||||
/*_____________________________________________fonction validation minute____________________________*/
|
||||
int VAL_MINUTE(int MINUTE)
|
||||
{
|
||||
if (MINUTE>59){
|
||||
MINUTE=0;
|
||||
};
|
||||
if (MINUTE<0){
|
||||
MINUTE=59;
|
||||
};
|
||||
return MINUTE;
|
||||
}
|
||||
/*_____________________________________________fonction validation heure____________________________*/
|
||||
int VAL_HEURE(int HEURE)
|
||||
{
|
||||
if (HEURE>23){
|
||||
HEURE=0;
|
||||
};
|
||||
if (HEURE<0){
|
||||
HEURE=23;
|
||||
};
|
||||
return HEURE;
|
||||
}
|
||||
/*_____________________________________________fonction validation mois____________________________*/
|
||||
int VAL_MOIS(int MOIS)
|
||||
{
|
||||
if (MOIS>12){
|
||||
MOIS=1;
|
||||
};
|
||||
if (MOIS<1){
|
||||
MOIS=12;
|
||||
};
|
||||
return MOIS;
|
||||
}
|
||||
/*_____________________________________________fonction validation annee____________________________*/
|
||||
int VAL_ANNEE(int ANNEE)
|
||||
{
|
||||
if (ANNEE>2100){
|
||||
ANNEE=2012;
|
||||
};
|
||||
if (ANNEE<1){
|
||||
ANNEE=2012;
|
||||
};
|
||||
return ANNEE;
|
||||
}
|
||||
/*_____________________________________________fonction validation jour____________________________*/
|
||||
|
||||
int VAL_JOUR(int JOUR, int MOIS, int ANNEE)
|
||||
{
|
||||
if (MOIS==1||MOIS==3||MOIS==5||MOIS==7||MOIS==8||MOIS==10||MOIS==12){
|
||||
if (JOUR<1){
|
||||
JOUR=31;
|
||||
};
|
||||
if (JOUR>31){
|
||||
JOUR=1;
|
||||
};
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
if (MOIS==4||MOIS==6||MOIS==9||MOIS==11){
|
||||
if (JOUR<1){
|
||||
JOUR=30;
|
||||
};
|
||||
if (JOUR>30){
|
||||
JOUR=1;
|
||||
};
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
if (MOIS==2&&bisex(ANNEE)==true){
|
||||
if (JOUR<1){
|
||||
JOUR=29;
|
||||
};
|
||||
if (JOUR>29){
|
||||
JOUR=1;
|
||||
};
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
if (MOIS==2&&bisex(ANNEE)==false){
|
||||
if (JOUR<1){
|
||||
JOUR=28;
|
||||
};
|
||||
if (JOUR>28){
|
||||
JOUR=1;
|
||||
};
|
||||
};
|
||||
|
||||
return JOUR;
|
||||
}
|
||||
bool bisex(int annee){
|
||||
//ce qui suit permet de determiner si l'annéee et bisextile renvoi vrai ou faux
|
||||
int r1;
|
||||
if(annee%400==0){
|
||||
r1=1;
|
||||
}
|
||||
else{
|
||||
r1=0;
|
||||
};
|
||||
int r2;
|
||||
if(annee%100==0){
|
||||
r2=1;
|
||||
}
|
||||
else{
|
||||
r2=0;
|
||||
};
|
||||
int r3;
|
||||
if(annee%4==0){
|
||||
r3=1;
|
||||
}
|
||||
else{
|
||||
r3=0;
|
||||
};
|
||||
int reponse;
|
||||
if(r1-r2+r3==1){
|
||||
reponse=true;
|
||||
}
|
||||
else{
|
||||
reponse=false;
|
||||
};
|
||||
|
||||
return reponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*_____________________________________________fonction evenement____________________________*/
|
||||
|
||||
boolean Evenement(Date*date_1,Date*date){
|
||||
boolean reponse=false;
|
||||
|
||||
if( (date->a-date_1->a)==0 && (date->m-date_1->m)==0 &&(date->j-date_1->j)>=0){
|
||||
reponse=true;//Serial.println(" 1 Vrai");
|
||||
}else if((date->a-date_1->a)==0 && (date->m-date_1->m)>=0){
|
||||
reponse=true;//Serial.println(" 2 Vrai");
|
||||
}
|
||||
else if((date->a-date_1->a)>0){
|
||||
reponse=true;//Serial.println(" 3 Vrai");
|
||||
}else{//Serial.println(" faux");
|
||||
}
|
||||
|
||||
return reponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*_____________________________________________fonction evenement____________________________*/
|
||||
|
||||
boolean Evenement(int j_1,int m_1,int a_1,int j,int m,int a){
|
||||
boolean reponse=false;
|
||||
|
||||
if( (a-a_1)==0 && (m-m_1)==0 &&(j-j_1)>=0){
|
||||
reponse=true;//Serial.println(" 1 Vrai");
|
||||
}else if((a-a_1)==0 && (m-m_1)>=0){
|
||||
reponse=true;//Serial.println(" 2 Vrai");
|
||||
}
|
||||
else if((a-a_1)>0){
|
||||
reponse=true;//Serial.println(" 3 Vrai");
|
||||
}else{//Serial.println(" faux");
|
||||
}
|
||||
|
||||
return reponse;
|
||||
}
|
||||
|
||||
/*_____________________________________________fonction evenement____________________________*/
|
||||
|
||||
boolean Evenement(int j_1,int m_1,int a_1,Date*date){
|
||||
boolean reponse=false;
|
||||
|
||||
|
||||
if( (date->a-a_1)==0 && (date->m-m_1)==0 &&(date->j-j_1)>=0){
|
||||
reponse=true;//Serial.println(" 1 Vrai");
|
||||
}else if((date->a-a_1)==0 && (date->m-m_1)>=0){
|
||||
reponse=true;//Serial.println(" 2 Vrai");
|
||||
}
|
||||
else if((date->a-a_1)>0){
|
||||
reponse=true;//Serial.println(" 3 Vrai");
|
||||
}else{//Serial.println(" faux");
|
||||
}
|
||||
|
||||
return reponse;
|
||||
}
|
||||
|
||||
/*_____________________________________________fonction evenement____________________________*/
|
||||
boolean Momment(int heure, int minute, int seconde ,Heure*Hrtc){
|
||||
boolean reponse=false;
|
||||
|
||||
if( (Hrtc->h-heure)==0 && (Hrtc->m-minute)==0 &&(Hrtc->s-seconde)>=0){
|
||||
reponse=true;
|
||||
}
|
||||
if( (Hrtc->h-heure)==0 && (Hrtc->m-minute)>=0){
|
||||
reponse=true;
|
||||
}
|
||||
if((Hrtc->h-heure)>0){
|
||||
reponse=true;
|
||||
}
|
||||
#ifdef DEBUG_SERIAL
|
||||
if (reponse==true){
|
||||
Serial.println(F("Momment OK"));
|
||||
}
|
||||
else{
|
||||
Serial.println(F(" Momment pas OK"));
|
||||
};
|
||||
#endif
|
||||
return reponse;
|
||||
}
|
||||
|
||||
|
||||
/*_____________________________________________fonction evenement____________________________*/
|
||||
boolean Momment(Heure*heure_T,Heure*heure){
|
||||
boolean reponse=false;
|
||||
|
||||
if( (heure->h-heure_T->h)==0 && (heure->m-heure_T->m)==0 &&(heure->s-heure_T->s)>=0){
|
||||
reponse=true;
|
||||
}
|
||||
if( (heure->h-heure_T->h)==0 && (heure->m-heure_T->m)>=0){
|
||||
reponse=true;
|
||||
}
|
||||
if((heure->h-heure_T->h)>0){
|
||||
reponse=true;
|
||||
}
|
||||
#ifdef DEBUG_SERIAL
|
||||
if (reponse==true){
|
||||
Serial.println(F("Momment OK"));
|
||||
}
|
||||
else{
|
||||
Serial.println(F(" Momment pas OK"));
|
||||
};
|
||||
#endif
|
||||
return reponse;
|
||||
}
|
||||
/*_____________________________________________fonction convertion de long heur en heur minute seconde____________________________*/
|
||||
void convertHeur(long *h,int *heure, int *minute,int *seconde){
|
||||
|
||||
*heure=(*h/3600);//heure entiere
|
||||
*minute=(*h/60)-((*heure)*60);// les minute entiere
|
||||
*seconde=*h-((*minute)*60)-(((*heure)*60)); //les seconde entiere
|
||||
|
||||
return;
|
||||
}
|
||||
62
SOLAIRE_TRACKER/Date_heure.h
Normal file
62
SOLAIRE_TRACKER/Date_heure.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
|
||||
cr<EFBFBD>ation : 16/10/2012
|
||||
version : 1.0 Cr<43>ation biblioth<74>que Date_heure
|
||||
auteur : Christophe Boulic
|
||||
support : Arduino Mega
|
||||
*/
|
||||
/*
|
||||
La bibliotheque a pour but de fournire des fonction de base pour controler la creation d'horaire ou de date
|
||||
Les fonctions implant<6E>es sont :
|
||||
- VAL_MINUTE X contrain la variable entre 0 et 59
|
||||
- VAL_HEURE X contrain la variable entre 0 et 23
|
||||
- VAL_MOIS X contrain la variable entre 1 et 12
|
||||
- VAL_JOUR X contrain la variable entre 1 et 365
|
||||
- VAL_ANNEE X contrain la variable entre 2000 et 2100
|
||||
- bisex X verifi si une annee est bisextile
|
||||
|
||||
*/
|
||||
//*************************************************************************************
|
||||
//Directives
|
||||
//*************************************************************************************
|
||||
#ifndef DATE_HEURE_H
|
||||
#define DATE_HEURE_H
|
||||
#include <Arduino.h>
|
||||
typedef struct Date Date;
|
||||
struct Date
|
||||
{
|
||||
int j;//jour
|
||||
int m;//mois
|
||||
int a;//annee
|
||||
};
|
||||
|
||||
typedef struct Heure Heure;
|
||||
struct Heure
|
||||
{
|
||||
int h;//heure
|
||||
int m;//Minute
|
||||
int s;//seconde
|
||||
};
|
||||
|
||||
|
||||
/*_____________________________________________fonction validation heure____________________________*/
|
||||
bool bisex(int annee);
|
||||
/*_____________________________________________fonction validation heure____________________________*/
|
||||
int VAL_MINUTE(int MINUTE);
|
||||
/*_____________________________________________fonction validation heure____________________________*/
|
||||
int VAL_HEURE(int HEURE);
|
||||
/*_____________________________________________fonction validation mois____________________________*/
|
||||
int VAL_MOIS(int MOIS);
|
||||
/*_____________________________________________fonction validation annee____________________________*/
|
||||
int VAL_ANNEE(int ANNEE);
|
||||
/*_____________________________________________fonction validation jour____________________________*/
|
||||
|
||||
int VAL_JOUR(int JOUR, int MOIS, int ANNEE);
|
||||
|
||||
boolean Evenement(Date*date_1,Date*date);
|
||||
boolean Evenement(int j_1,int m_1,int a_1,int j,int m,int a);
|
||||
boolean Evenement(int j_1,int m_1,int a_1,Date*date);
|
||||
boolean Momment(int heure, int minute, int seconde ,Heure*Hrtc);
|
||||
boolean Momment(Heure*heure_T,Heure*heure);
|
||||
void convertHeur(long*h,int *heure, int *minute,int *seconde);
|
||||
#endif // DATE_HEURE_H
|
||||
137
SOLAIRE_TRACKER/SOLAIRE_TRACKER.ino
Normal file
137
SOLAIRE_TRACKER/SOLAIRE_TRACKER.ino
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "Date_heure.h"
|
||||
#include "ephemeride.h"
|
||||
|
||||
// Load the virtuabotixRTC library
|
||||
//#include "virtuabotixRTC.h"
|
||||
|
||||
// Determine the pins connected to the module
|
||||
// myRTC (clock, data, RST)
|
||||
//virtuabotixRTC myRTC (6, 7, 8);
|
||||
int PWMA=5;//Right side
|
||||
int PWMB=4;//Left side
|
||||
int DA=0;//Right reverse
|
||||
int DB=2;//Left reverse
|
||||
|
||||
void setup() {
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
Serial.begin(9600);
|
||||
pinMode(PWMA, OUTPUT);
|
||||
pinMode(PWMB, OUTPUT);
|
||||
pinMode(DA, OUTPUT);
|
||||
pinMode(DB, OUTPUT);
|
||||
stop();
|
||||
// After to set the entire information, comment the following line
|
||||
// (seconds, minutes, hours, day of week, day of month, month, year)
|
||||
// myRTC.setDS1302Time (0, 18, 23, 6, 31, 7, 2021);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Reads the information from the CI
|
||||
// myRTC.updateTime ();
|
||||
// printTime();
|
||||
//
|
||||
// Serial.print("rang=");
|
||||
// int N = rangJour(myRTC.dayofmonth,myRTC.month,myRTC.year);
|
||||
// Serial.println(N);
|
||||
//
|
||||
// Serial.print("declinaison=");
|
||||
// Serial.println(declinaisonSolaire(N));
|
||||
//
|
||||
//
|
||||
// Serial.print("angleHoraireSoeil=");
|
||||
// Serial.println(angleHoraireSoeil(N, 47.728));
|
||||
|
||||
avance();
|
||||
delay(10000); // wait for a second
|
||||
Serial.println("off");
|
||||
recule();
|
||||
delay(10000); // wait for a second
|
||||
Serial.println("On");
|
||||
|
||||
stop();
|
||||
delay(10000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void printTime()
|
||||
{
|
||||
// Print the details in serial monitor
|
||||
// Serial.print
|
||||
// ("Data "); // Call the routine that prints the day of the week
|
||||
// imprime_dia_da_semana (myRTC.dayofweek);
|
||||
// Serial.print (", ");
|
||||
// Serial.print (myRTC.dayofmonth);
|
||||
// Serial.print ("/");
|
||||
// Serial.print (myRTC.month);
|
||||
// Serial.print ("/");
|
||||
// Serial.print (myRTC.year);
|
||||
// Serial.print ("");
|
||||
// Serial.print
|
||||
// (" Time "); // Adds a 0 if the time value is <10
|
||||
// if (myRTC.hours <10)
|
||||
// {
|
||||
// Serial.print ("0");
|
||||
// }
|
||||
// Serial.print (myRTC.hours);
|
||||
// Serial.print
|
||||
// (":"); // Adds a 0 if the value of the minutes is <10
|
||||
// if (myRTC.minutes <10)
|
||||
// {
|
||||
// Serial.print ("0");
|
||||
// }
|
||||
// Serial.print (myRTC.minutes);
|
||||
// Serial.print
|
||||
// (":"); // Adds a 0 if the value of the latter is <10
|
||||
// if (myRTC.seconds <10)
|
||||
// {
|
||||
// Serial.print ("0");
|
||||
// }
|
||||
// Serial.println (myRTC.seconds);
|
||||
|
||||
}
|
||||
void stop()
|
||||
{
|
||||
digitalWrite(PWMA, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
digitalWrite(DA, LOW);
|
||||
}
|
||||
|
||||
void avance() {
|
||||
digitalWrite(PWMA, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
digitalWrite(DA, HIGH);
|
||||
}
|
||||
|
||||
void recule() {
|
||||
digitalWrite(PWMA, HIGH);
|
||||
|
||||
digitalWrite(DA, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
}
|
||||
|
||||
void imprime_dia_da_semana (int day)
|
||||
{
|
||||
switch (day)
|
||||
{
|
||||
case 1:
|
||||
Serial.print
|
||||
("Sunday");
|
||||
break; case 2:
|
||||
Serial.print
|
||||
("Second");
|
||||
break; case 3:
|
||||
Serial.print
|
||||
("Terca");
|
||||
break; case 4:
|
||||
Serial.print
|
||||
("Wednesday");
|
||||
break; case 5:
|
||||
Serial.print
|
||||
("Quinta");
|
||||
break; case 6:
|
||||
Serial.print
|
||||
("Friday");
|
||||
break; case 7:
|
||||
Serial.print
|
||||
("Saturday"); break;
|
||||
}
|
||||
}
|
||||
77
SOLAIRE_TRACKER/ephemeride.cpp
Normal file
77
SOLAIRE_TRACKER/ephemeride.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "ephemeride.h"
|
||||
#include <math.h>
|
||||
#include "Date_heure.h"
|
||||
|
||||
#define PI (4.0 * atan(1.0))
|
||||
//const double PI = 4.0 * atan(1.0);
|
||||
|
||||
/*______________________________________________________________fonction qui calcule le rang du jour de l'année__________________________*/
|
||||
///////////////////////////////////////////////////// N1,N2,K sont des parametre de calcule//////////////////////////////////////////
|
||||
|
||||
int rangJour(int day,int month,int year){
|
||||
|
||||
int N1= int((month*275)/9);
|
||||
int N2=int((month+9)/12);
|
||||
int K;
|
||||
|
||||
if (bisex(year)==true){
|
||||
K=1;
|
||||
}
|
||||
else{
|
||||
K=2;
|
||||
|
||||
};
|
||||
int N=N1-N2*K+day-30;
|
||||
return N;
|
||||
}
|
||||
/*_____________________________________________________________fonction qui calcule l'equation du temps_________________________________*/
|
||||
|
||||
////////////////////////////////////////////////////////,M,C,L,R sont des parametre de calcule en degré,/////////////////////////////
|
||||
//////////////////////////////////////////////////eqt=equation de temps en minute conversion en radian=x*PI/180//////////////////////
|
||||
float equationDuTemps(int N){
|
||||
|
||||
float M=(357+0.9856*N) - 360*int((357+0.9856*N)/360);
|
||||
float C= 1.914*sin(M*PI/180)+0.02*sin(2*M*PI/180);
|
||||
float L= (280+C+0.9856*N) - 360*int((280+C+0.9856*N)/360);
|
||||
float R=-2.466*sin(PI/180*2*L)+0.053*sin(PI/180*4*L);
|
||||
float eqt=(C+R)*4;
|
||||
return eqt;
|
||||
}
|
||||
|
||||
/*_____________________________________________________________fonction qui calcul la declinaison solaire_______________________________*/
|
||||
/////////////////////////////////////////////////////////////////////////calcule de la declinaison solaire dec///////////////////////
|
||||
////////////////////////////
|
||||
float declinaisonSolaire(int N){
|
||||
float M=(357+0.9856*N) - 360*int((357+0.9856*N)/360);
|
||||
float C= 1.914*sin(M*PI/180)+0.02*sin(2*M*PI/180);
|
||||
float L= (280+C+0.9856*N) - 360*int((280+C+0.9856*N)/360);
|
||||
float dec=asin(0.3978*sin(PI/180*L))*180/PI;
|
||||
return dec;
|
||||
}
|
||||
|
||||
|
||||
/*_____________________________________________________________fonction qui calcul HO l'angle horaire du soeil_______________________________*/
|
||||
|
||||
|
||||
float angleHoraireSoeil(int N, float LATITUDE){
|
||||
|
||||
float M=(357+0.9856*N) - 360*int((357+0.9856*N)/360);
|
||||
float C= 1.914*sin(M*PI/180)+0.02*sin(2*M*PI/180);
|
||||
float L= (280+C+0.9856*N) - 360*int((280+C+0.9856*N)/360);
|
||||
float R=-2.466*sin(PI/180*2*L)+0.053*sin(PI/180*4*L);
|
||||
float eqt=(C+R)*4;
|
||||
float dec=asin(0.3978*sin(PI/180*L))*180/PI;
|
||||
float ho=acos((-0.01405-sin(PI/180*dec)*sin(PI/180*LATITUDE))/(cos(PI/180*dec)*cos(PI/180*LATITUDE)))*180/PI;
|
||||
|
||||
return ho;
|
||||
}
|
||||
|
||||
float azimut(int N, float LATITUDE){
|
||||
|
||||
return (acos((-0.01405*sin(PI/180*LATITUDE )-sin(PI/180*(declinaisonSolaire(N))))/cos(PI/180*LATITUDE)))*180/PI;
|
||||
|
||||
}
|
||||
/*__fonction qui calcul S que fait la trajectoire du Soleil avec l'horizon aux moments des lever/coucher__ */
|
||||
float angleS(int N, float LATITUDE){
|
||||
return (acos(sin(PI/180*LATITUDE )/cos(PI/180*(declinaisonSolaire(N)))))*180/PI;
|
||||
}
|
||||
10
SOLAIRE_TRACKER/ephemeride.h
Normal file
10
SOLAIRE_TRACKER/ephemeride.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef EPHEMERIDE_H_INCLUDED
|
||||
#define EPHEMERIDE_H_INCLUDED
|
||||
|
||||
int rangJour(int day,int month,int year);//renvoi le rang du jour
|
||||
float equationDuTemps(int N);// renvoi l'equation de temps
|
||||
float declinaisonSolaire(int N);//renvoi la declinaison solaire
|
||||
float angleHoraireSoeil(int N, float LATITUDE);// renvoi l'angle horaire du soleil
|
||||
float azimut(int N, float LATITUDE);
|
||||
float angleS(int N, float LATITUDE);
|
||||
#endif // EPHEMERIDE_H_INCLUDED
|
||||
Reference in New Issue
Block a user