Pimp the code
Redone all The correct indentation and added some modifications
This commit is contained in:
parent
ba9513a33e
commit
8917b9aac6
@ -1,45 +1,43 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#define WindSensorPin (2)
|
||||||
#define WindSensorPin (2) // The pin location of the anemometer sensor
|
|
||||||
|
|
||||||
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
|
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
|
||||||
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
|
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
|
||||||
|
|
||||||
float WindSpeed; // speed miles per hour
|
float WindSpeed; // speed miles per hour
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
Serial.begin(9600);
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
pinMode(WindSensorPin, INPUT);
|
pinMode(WindSensorPin, INPUT);
|
||||||
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
|
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
|
||||||
|
|
||||||
Serial.println("Rotations\tKm/h");
|
Serial.println("Rotations\tKm/h");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
|
Rotations = 0; // Set Rotations count to 0 ready for calculations
|
||||||
|
|
||||||
Rotations = 0; // Set Rotations count to 0 ready for calculations
|
sei(); // Enables interrupts
|
||||||
|
delay (3000); // Wait 3 seconds to average
|
||||||
|
cli(); // Disable interrupts
|
||||||
|
|
||||||
sei(); // Enables interrupts
|
// convert to mp/h using the formula V=P(2.25/T)
|
||||||
delay (3000); // Wait 3 seconds to average
|
// V = P(2.25/3) = P * 0.75
|
||||||
cli(); // Disable interrupts
|
|
||||||
|
|
||||||
// convert to mp/h using the formula V=P(2.25/T)
|
WindSpeed = (Rotations * 0.75) * 1.609344;
|
||||||
// V = P(2.25/3) = P * 0.75
|
|
||||||
|
|
||||||
WindSpeed = (Rotations * 0.75) * 1.609344;
|
|
||||||
|
|
||||||
Serial.print(Rotations); Serial.print("\t\t");
|
|
||||||
Serial.println(WindSpeed);
|
|
||||||
|
|
||||||
|
Serial.print(Rotations); Serial.print("\t\t");
|
||||||
|
Serial.println(WindSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the function that the interrupt calls to increment the rotation count
|
// This is the function that the interrupt calls to increment the rotation count
|
||||||
void isr_rotation () {
|
void isr_rotation()
|
||||||
|
{
|
||||||
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
|
if ((millis() - ContactBounceTime) > 15 ) // debounce the switch contact.
|
||||||
Rotations++;
|
{
|
||||||
ContactBounceTime = millis();
|
Rotations++;
|
||||||
}
|
ContactBounceTime = millis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,25 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
#define WindSensorPin (2)
|
#define WindSensorPin (2)
|
||||||
|
|
||||||
|
|
||||||
volatile unsigned long Rotations;
|
volatile unsigned long Rotations;
|
||||||
volatile unsigned long ContactBounceTime;
|
volatile unsigned long ContactBounceTime;
|
||||||
|
|
||||||
|
unsigned long duration;
|
||||||
|
|
||||||
float WindSpeed;
|
float WindSpeed;
|
||||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD4, 0x22 };// @dresse MAC de votre Arduino Ethernet
|
float T = 0;
|
||||||
byte ip[] = {10,66,240,59};
|
|
||||||
//char server[] = "spe.sin.apo.free.fr"; // nom du site
|
byte mac[] = {0x90, 0xA2, 0xDA, 0x0E, 0xD4, 0x22}; // @Arduino Ethernet
|
||||||
char server[] = "10.66.240.81"; // @PC en local quand on utilise WAMPSERVEUR
|
byte ip[] = {10, 66, 240, 59};
|
||||||
|
|
||||||
|
char server[] = "10.66.240.81"; // @PC
|
||||||
|
|
||||||
String readString;
|
String readString;
|
||||||
Servo monServomoteur;
|
boolean drapeau = false;
|
||||||
boolean drapeau= false;
|
|
||||||
|
|
||||||
int D;
|
int D;
|
||||||
int LE;
|
int LE;
|
||||||
int LI;
|
int LI;
|
||||||
@ -21,316 +29,334 @@ int S;
|
|||||||
int AM;
|
int AM;
|
||||||
char c;
|
char c;
|
||||||
int pin = 9;
|
int pin = 9;
|
||||||
unsigned long duration;
|
int position = 0;
|
||||||
int position = 0 ;
|
|
||||||
float T = 0;
|
int F = 1 / T;
|
||||||
int F = 1/T;
|
|
||||||
int Led = 7;
|
int Led = 7;
|
||||||
int bLed = 3;
|
int bLed = 3;
|
||||||
int gLed = 4;
|
int gLed = 4;
|
||||||
int rLed = 6;
|
int rLed = 6;
|
||||||
int ST;
|
int ST;
|
||||||
|
|
||||||
EthernetClient client;
|
EthernetClient client;
|
||||||
|
|
||||||
|
void setup()
|
||||||
void setup() {
|
{
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
pinMode(bLed, OUTPUT);
|
pinMode(bLed, OUTPUT);
|
||||||
pinMode(gLed, OUTPUT);
|
pinMode(gLed, OUTPUT);
|
||||||
pinMode(rLed, OUTPUT);
|
pinMode(rLed, OUTPUT);
|
||||||
pinMode(Led, OUTPUT);
|
pinMode(Led, OUTPUT);
|
||||||
monServomoteur.attach(8);
|
monServomoteur.attach(8);
|
||||||
Serial.begin(9600);// mise en marche liaison série
|
Serial.begin(9600); // mise en marche liaison série
|
||||||
//Ethernet.begin(mac, ip);
|
//Ethernet.begin(mac, ip);
|
||||||
if (Ethernet.begin(mac) == 0) {
|
if (Ethernet.begin(mac) == 0)
|
||||||
|
{
|
||||||
Serial.println("Failed to configure Ethernet using DHCP");
|
Serial.println("Failed to configure Ethernet using DHCP");
|
||||||
// no point in carrying on, so do nothing forevermore:
|
// no point in carrying on, so do nothing forevermore:
|
||||||
for(;;);}
|
for (;;)
|
||||||
delay(2000);
|
;
|
||||||
Serial.println("connecting...");
|
}
|
||||||
}
|
delay(2000);
|
||||||
|
Serial.println("connecting...");
|
||||||
void loop(){
|
|
||||||
//Luxmetre
|
|
||||||
delay(500);
|
|
||||||
duration = pulseIn(pin, HIGH);
|
|
||||||
T = 2*duration;
|
|
||||||
Serial.print("Luminosite (lux): ");
|
|
||||||
F = 1000000*1/T;
|
|
||||||
Serial.println(F, DEC);
|
|
||||||
//Anemometre
|
|
||||||
Rotations = 0;
|
|
||||||
sei();
|
|
||||||
delay (3000);
|
|
||||||
cli();
|
|
||||||
WindSpeed = (Rotations * 0.75) * 1.609344;
|
|
||||||
Serial.print(Rotations); Serial.print("\t\t");
|
|
||||||
Serial.println(WindSpeed);
|
|
||||||
|
|
||||||
envoieBDD();
|
|
||||||
LectureBDD();
|
|
||||||
Traitement();
|
|
||||||
}
|
}
|
||||||
void isr_rotation () {
|
|
||||||
|
|
||||||
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
|
void loop()
|
||||||
Rotations++;
|
{
|
||||||
ContactBounceTime = millis();
|
//Luxmetre
|
||||||
|
delay(500);
|
||||||
|
duration = pulseIn(pin, HIGH);
|
||||||
|
T = 2 * duration;
|
||||||
|
Serial.print("Luminosite (lux): ");
|
||||||
|
F = 1000000 * 1 / T;
|
||||||
|
Serial.println(F, DEC);
|
||||||
|
//Anemometre
|
||||||
|
Rotations = 0;
|
||||||
|
sei();
|
||||||
|
delay(3000);
|
||||||
|
cli();
|
||||||
|
WindSpeed = (Rotations * 0.75) * 1.609344;
|
||||||
|
Serial.print(Rotations);
|
||||||
|
Serial.print("\t\t");
|
||||||
|
Serial.println(WindSpeed);
|
||||||
|
|
||||||
|
envoieBDD();
|
||||||
|
LectureBDD();
|
||||||
|
Traitement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void isr_rotation()
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((millis() - ContactBounceTime) > 15)
|
||||||
|
{ // debounce the switch contact.
|
||||||
|
Rotations++;
|
||||||
|
ContactBounceTime = millis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void envoieBDD()
|
void envoieBDD()
|
||||||
{
|
{
|
||||||
if (client.connect(server, 80)) {
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
client.print("GET /SLEGPI/ecriture.php?lux=");
|
client.print("GET /SLEGPI/ecriture.php?lux=");
|
||||||
client.print(F);
|
client.print(F);
|
||||||
client.println(" HTTP/1.1");
|
client.println(" HTTP/1.1");
|
||||||
client.println("Host: 10.66.240.81");
|
client.println("Host: 10.66.240.81");
|
||||||
Serial.println(F);
|
Serial.println(F);
|
||||||
Serial.println( "Connection: close" );
|
Serial.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
client.stop();
|
client.stop();
|
||||||
client.println();
|
client.println();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.connect(server, 80)) {
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
client.print("GET /SLEGPI/ecriture.php?vent=");
|
client.print("GET /SLEGPI/ecriture.php?vent=");
|
||||||
client.print(WindSpeed);
|
client.print(WindSpeed);
|
||||||
client.println(" HTTP/1.1");
|
client.println(" HTTP/1.1");
|
||||||
client.println("Host: 10.66.240.81");
|
client.println("Host: 10.66.240.81");
|
||||||
//Serial.println(F);
|
//Serial.println(F);
|
||||||
Serial.println( "Connection: close" );
|
Serial.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
client.stop();
|
client.stop();
|
||||||
client.println();
|
client.println();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void LectureBDD()
|
void LectureBDD()
|
||||||
{
|
{
|
||||||
EthernetServer server(80);
|
EthernetServer server(80);
|
||||||
server.available();
|
server.available();
|
||||||
EthernetClient client = server.available();
|
EthernetClient client = server.available();
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
Serial.println("attente serveur");
|
Serial.println("attente serveur");
|
||||||
while (client.connected())
|
while (client.connected())
|
||||||
{
|
{
|
||||||
client.println("z"); //pour la connexion
|
client.println("z"); //pour la connexion
|
||||||
while (client.available()) // Not if - you want to read all the data
|
while (client.available()) // Not if - you want to read all the data
|
||||||
{
|
{
|
||||||
char c = client.read();//lecture caractère par caractère
|
char c = client.read(); //lecture caractère par caractère
|
||||||
//on concatène les caractères et on ne sélectionne qu'un string total de longueur < 40
|
//on concatène les caractères et on ne sélectionne qu'un string total de longueur < 40
|
||||||
if (readString.length()<40 ) readString.concat(c);
|
if (readString.length() < 40)
|
||||||
// détection de fin de ligne
|
readString.concat(c);
|
||||||
if (c == '\n' )
|
// détection de fin de ligne
|
||||||
{
|
if (c == '\n')
|
||||||
Serial.println (readString);//écriture des 40 caractères dans le terminal série
|
{
|
||||||
// index des recherches des mots "ON" et "OUV" dans la chaine readString
|
Serial.println(readString); //écriture des 40 caractères dans le terminal série
|
||||||
// si absent alors =-1
|
// index des recherches des mots "ON" et "OUV" dans la chaine readString
|
||||||
LI = readString.indexOf('Y');
|
// si absent alors =-1
|
||||||
LE = readString.indexOf('Z');
|
LI = readString.indexOf('Y');
|
||||||
S = readString.indexOf('OUV');
|
LE = readString.indexOf('Z');
|
||||||
AM = readString.indexOf('WW');
|
S = readString.indexOf('OUV');
|
||||||
readString="";//initialisation de la variable chaîne readString
|
AM = readString.indexOf('WW');
|
||||||
client.stop();//deconnection de l'arduino
|
readString = ""; //initialisation de la variable chaîne readString
|
||||||
Serial.println();
|
client.stop(); //deconnection de l'arduino
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Traitement()
|
void Traitement()
|
||||||
{
|
{
|
||||||
if(AM >0){
|
if (AM > 0)
|
||||||
Serial.println("Mode automatique");
|
{
|
||||||
|
Serial.println("Mode automatique");
|
||||||
|
|
||||||
if(F <1000){
|
if (F < 1000)
|
||||||
digitalWrite(bLed, HIGH);
|
{
|
||||||
digitalWrite(gLed, HIGH);
|
digitalWrite(bLed, HIGH);
|
||||||
digitalWrite(rLed, HIGH);
|
digitalWrite(gLed, HIGH);
|
||||||
digitalWrite(Led, LOW);
|
digitalWrite(rLed, HIGH);
|
||||||
if (drapeau==true)
|
digitalWrite(Led, LOW);
|
||||||
{
|
if (drapeau == true)
|
||||||
drapeau=false;
|
{
|
||||||
position=0;
|
drapeau = false;
|
||||||
monServomoteur.write(position);
|
position = 0;
|
||||||
delay(15);
|
monServomoteur.write(position);
|
||||||
}
|
delay(15);
|
||||||
D=1;
|
|
||||||
ST=0;
|
|
||||||
//allumer
|
|
||||||
|
|
||||||
if (client.connect(server, 80)) {
|
|
||||||
Serial.println("connected");
|
|
||||||
Serial.println("toto");
|
|
||||||
client.print("GET /SLEGPI/ecriture.php?eInt=");
|
|
||||||
client.print(D);
|
|
||||||
Serial.println(D);
|
|
||||||
client.println(" HTTP/1.1");
|
|
||||||
client.println("Host: 10.66.240.81");
|
|
||||||
Serial.println(F);
|
|
||||||
Serial.println( "Connection: close" );
|
|
||||||
client.println();
|
|
||||||
client.stop();
|
|
||||||
client.println();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.println("connection failed");
|
|
||||||
}
|
|
||||||
if (client.connect(server, 80)) {
|
|
||||||
Serial.println("connected");
|
|
||||||
client.print("GET /SLEGPI/ecriture.php?eExt=");
|
|
||||||
client.print(D);
|
|
||||||
client.println(" HTTP/1.1");
|
|
||||||
client.println("Host: 10.66.240.81");
|
|
||||||
Serial.println(1);
|
|
||||||
Serial.println( "Connection: close" );
|
|
||||||
client.println();
|
|
||||||
client.stop();
|
|
||||||
client.println();
|
|
||||||
}
|
}
|
||||||
if (client.connect(server, 80)) {
|
D = 1;
|
||||||
Serial.println("connected");
|
ST = 0;
|
||||||
client.print("GET /SLEGPI/ecriture.php?Store=");
|
//allumer
|
||||||
client.print(ST);
|
|
||||||
client.println(" HTTP/1.1");
|
if (client.connect(server, 80))
|
||||||
client.println("Host: 10.66.240.81");
|
{
|
||||||
Serial.println(1);
|
Serial.println("connected");
|
||||||
Serial.println( "Connection: close" );
|
Serial.println("toto");
|
||||||
client.println();
|
client.print("GET /SLEGPI/ecriture.php?eInt=");
|
||||||
client.stop();
|
client.print(D);
|
||||||
client.println();
|
Serial.println(D);
|
||||||
|
client.println(" HTTP/1.1");
|
||||||
|
client.println("Host: 10.66.240.81");
|
||||||
|
Serial.println(F);
|
||||||
|
Serial.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
client.stop();
|
||||||
|
client.println();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
Serial.println("connection failed");
|
||||||
|
}
|
||||||
if(F >1000){
|
if (client.connect(server, 80))
|
||||||
digitalWrite(bLed, LOW);
|
{
|
||||||
digitalWrite(gLed, LOW);
|
Serial.println("connected");
|
||||||
digitalWrite(rLed, LOW);
|
client.print("GET /SLEGPI/ecriture.php?eExt=");
|
||||||
digitalWrite(Led, HIGH);
|
client.print(D);
|
||||||
if (drapeau==false)
|
client.println(" HTTP/1.1");
|
||||||
{
|
client.println("Host: 10.66.240.81");
|
||||||
drapeau=true;
|
Serial.println(1);
|
||||||
for (int position = 0; position <= 180; position++)
|
Serial.println("Connection: close");
|
||||||
{
|
client.println();
|
||||||
monServomoteur.write(position);
|
client.stop();
|
||||||
delay(15);
|
client.println();
|
||||||
}
|
}
|
||||||
}
|
if (client.connect(server, 80))
|
||||||
D=0;
|
{
|
||||||
ST=1;
|
Serial.println("connected");
|
||||||
//et
|
client.print("GET /SLEGPI/ecriture.php?Store=");
|
||||||
if (client.connect(server, 80)) {
|
client.print(ST);
|
||||||
Serial.println("connected");
|
client.println(" HTTP/1.1");
|
||||||
Serial.println("toto");
|
client.println("Host: 10.66.240.81");
|
||||||
client.print("GET /SLEGPI/ecriture.php?eInt=");
|
Serial.println(1);
|
||||||
client.print(D);
|
Serial.println("Connection: close");
|
||||||
Serial.println(D);
|
client.println();
|
||||||
client.println(" HTTP/1.1");
|
client.stop();
|
||||||
client.println("Host: 10.66.240.81");
|
client.println();
|
||||||
Serial.println(F);
|
|
||||||
Serial.println( "Connection: close" );
|
|
||||||
client.println();
|
|
||||||
client.stop();
|
|
||||||
client.println();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.println("connection failed");
|
|
||||||
}
|
|
||||||
if (client.connect(server, 80)) {
|
|
||||||
Serial.println("connected");
|
|
||||||
client.print("GET /SLEGPI/ecriture.php?eExt=");
|
|
||||||
client.print(D);
|
|
||||||
client.println(" HTTP/1.1");
|
|
||||||
client.println("Host: 10.66.240.81");
|
|
||||||
Serial.println(1);
|
|
||||||
Serial.println( "Connection: close" );
|
|
||||||
client.println();
|
|
||||||
client.stop();
|
|
||||||
client.println();
|
|
||||||
}
|
}
|
||||||
if (client.connect(server, 80)) {
|
|
||||||
Serial.println("connected");
|
|
||||||
Serial.println("toto");
|
|
||||||
client.print("GET /SLEGPI/ecriture.php?Store=");
|
|
||||||
client.print(ST);
|
|
||||||
Serial.println(D);
|
|
||||||
client.println(" HTTP/1.1");
|
|
||||||
client.println("Host: 10.66.240.81");
|
|
||||||
Serial.println(F);
|
|
||||||
Serial.println( "Connection: close" );
|
|
||||||
client.println();
|
|
||||||
client.stop();
|
|
||||||
client.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //Allumer les lumieres exterieurs
|
|
||||||
else{
|
|
||||||
Serial.println("Mode manuel");
|
|
||||||
//Eteindre les lumieres exterieurs
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(LI >0){
|
|
||||||
digitalWrite(Led, LOW);
|
|
||||||
}//Allumer les lumieres exterieurs
|
|
||||||
else{
|
|
||||||
digitalWrite(Led, HIGH);
|
|
||||||
}//Eteindre les lumieres exterieurs
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(LE >0){
|
|
||||||
digitalWrite(bLed, HIGH);
|
|
||||||
digitalWrite(gLed, HIGH);
|
|
||||||
digitalWrite(rLed, HIGH);
|
|
||||||
}//Allumer les lumieres exterieurs
|
|
||||||
else{
|
|
||||||
digitalWrite(bLed, LOW);
|
|
||||||
digitalWrite(gLed, LOW);
|
|
||||||
digitalWrite(rLed, LOW);
|
|
||||||
}//Eteindre les lumieres exterieurs
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(S >0){
|
|
||||||
if (drapeau==false)
|
|
||||||
{
|
|
||||||
drapeau=true;
|
|
||||||
for (int position = 0; position <= 180; position++)
|
|
||||||
{
|
|
||||||
monServomoteur.write(position);
|
|
||||||
delay(15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//Monter le Store
|
|
||||||
else{
|
|
||||||
|
|
||||||
if (drapeau==true)
|
|
||||||
{
|
|
||||||
drapeau=false;
|
|
||||||
position=0;
|
|
||||||
monServomoteur.write(position);
|
|
||||||
delay(15);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}//Baisser le Store
|
|
||||||
|
|
||||||
|
if (F > 1000)
|
||||||
|
{
|
||||||
|
digitalWrite(bLed, LOW);
|
||||||
|
digitalWrite(gLed, LOW);
|
||||||
|
digitalWrite(rLed, LOW);
|
||||||
|
digitalWrite(Led, HIGH);
|
||||||
|
if (drapeau == false)
|
||||||
|
{
|
||||||
|
drapeau = true;
|
||||||
|
for (int position = 0; position <= 180; position++)
|
||||||
|
{
|
||||||
|
monServomoteur.write(position);
|
||||||
|
delay(15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
D = 0;
|
||||||
|
ST = 1;
|
||||||
|
//et
|
||||||
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
|
Serial.println("connected");
|
||||||
|
Serial.println("toto");
|
||||||
|
client.print("GET /SLEGPI/ecriture.php?eInt=");
|
||||||
|
client.print(D);
|
||||||
|
Serial.println(D);
|
||||||
|
client.println(" HTTP/1.1");
|
||||||
|
client.println("Host: 10.66.240.81");
|
||||||
|
Serial.println(F);
|
||||||
|
Serial.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
client.stop();
|
||||||
|
client.println();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("connection failed");
|
||||||
|
}
|
||||||
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
|
Serial.println("connected");
|
||||||
|
client.print("GET /SLEGPI/ecriture.php?eExt=");
|
||||||
|
client.print(D);
|
||||||
|
client.println(" HTTP/1.1");
|
||||||
|
client.println("Host: 10.66.240.81");
|
||||||
|
Serial.println(1);
|
||||||
|
Serial.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
client.stop();
|
||||||
|
client.println();
|
||||||
|
}
|
||||||
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
|
Serial.println("connected");
|
||||||
|
Serial.println("toto");
|
||||||
|
client.print("GET /SLEGPI/ecriture.php?Store=");
|
||||||
|
client.print(ST);
|
||||||
|
Serial.println(D);
|
||||||
|
client.println(" HTTP/1.1");
|
||||||
|
client.println("Host: 10.66.240.81");
|
||||||
|
Serial.println(F);
|
||||||
|
Serial.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
client.stop();
|
||||||
|
client.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //Allumer les lumieres exterieurs
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("Mode manuel");
|
||||||
|
//Eteindre les lumieres exterieurs
|
||||||
|
|
||||||
|
if (LI > 0)
|
||||||
|
{
|
||||||
|
digitalWrite(Led, LOW);
|
||||||
|
} //Allumer les lumieres exterieurs
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite(Led, HIGH);
|
||||||
|
} //Eteindre les lumieres exterieurs
|
||||||
|
|
||||||
|
if (LE > 0)
|
||||||
|
{
|
||||||
|
digitalWrite(bLed, HIGH);
|
||||||
|
digitalWrite(gLed, HIGH);
|
||||||
|
digitalWrite(rLed, HIGH);
|
||||||
|
} //Allumer les lumieres exterieurs
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite(bLed, LOW);
|
||||||
|
digitalWrite(gLed, LOW);
|
||||||
|
digitalWrite(rLed, LOW);
|
||||||
|
} //Eteindre les lumieres exterieurs
|
||||||
|
|
||||||
|
if (S > 0)
|
||||||
|
{
|
||||||
|
if (drapeau == false)
|
||||||
|
{
|
||||||
|
drapeau = true;
|
||||||
|
for (int position = 0; position <= 180; position++)
|
||||||
|
{
|
||||||
|
monServomoteur.write(position);
|
||||||
|
delay(15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Monter le Store
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
if (drapeau == true)
|
||||||
|
{
|
||||||
|
drapeau = false;
|
||||||
|
position = 0;
|
||||||
|
monServomoteur.write(position);
|
||||||
|
delay(15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //Baisser le Store
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
int pin = 10;
|
|
||||||
unsigned long duration;
|
unsigned long duration;
|
||||||
float T = 0;
|
float T = 0;
|
||||||
|
|
||||||
|
int pin = 10;
|
||||||
int F = 1/T;
|
int F = 1/T;
|
||||||
int led = 9;
|
int led = 9;
|
||||||
int BLUE = 6;
|
int BLUE = 6;
|
||||||
int GREEN = 3;
|
int GREEN = 3;
|
||||||
int RED = 5;
|
int RED = 5;
|
||||||
int brightness1 = 200;
|
int lum1 = 255;
|
||||||
int brightness2 = 255;
|
int lum0 = 0;
|
||||||
int brightness3 = 255;
|
|
||||||
int brightness4 = 0;
|
|
||||||
int brightness5 = 0;
|
|
||||||
int brightness6 = 0;
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -25,24 +22,23 @@ void loop()
|
|||||||
{
|
{
|
||||||
delay(1000);
|
delay(1000);
|
||||||
duration = pulseIn(pin, HIGH);
|
duration = pulseIn(pin, HIGH);
|
||||||
T = 2*duration;
|
T = 2*duration;
|
||||||
Serial.print("Luminosite (lux): ");
|
Serial.print("Luminosite (lux): ");
|
||||||
F = 1000000*1/T;
|
F = 1000000*1/T;
|
||||||
Serial.println(F, DEC);
|
Serial.println(F, DEC);
|
||||||
|
|
||||||
if (F >= 500)
|
if (F >= 500)
|
||||||
{
|
{
|
||||||
digitalWrite(led, HIGH);
|
digitalWrite(led, HIGH);
|
||||||
analogWrite(RED, brightness4);
|
analogWrite(RED, lum0);
|
||||||
analogWrite(GREEN, brightness5);
|
analogWrite(GREEN, lum0);
|
||||||
analogWrite(BLUE, brightness6);
|
analogWrite(BLUE, lum0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
digitalWrite(led, LOW);
|
digitalWrite(led, LOW);
|
||||||
analogWrite(RED, brightness1);
|
analogWrite(RED, lum1);
|
||||||
analogWrite(GREEN, brightness2);
|
analogWrite(GREEN, lum1);
|
||||||
analogWrite(BLUE, brightness3);
|
analogWrite(BLUE, lum1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,12 +2,16 @@
|
|||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#define WindSensorPin (2)
|
#define WindSensorPin (2)
|
||||||
|
|
||||||
|
|
||||||
volatile unsigned long Rotations;
|
volatile unsigned long Rotations;
|
||||||
volatile unsigned long ContactBounceTime;
|
volatile unsigned long ContactBounceTime;
|
||||||
float WindSpeed;
|
float WindSpeed;
|
||||||
int pin = 9;
|
|
||||||
unsigned long duration;
|
unsigned long duration;
|
||||||
float T = 0;
|
float T = 0;
|
||||||
|
|
||||||
|
int pin = 9;
|
||||||
int F = 1/T;
|
int F = 1/T;
|
||||||
int led = 8;
|
int led = 8;
|
||||||
int BLUE = 6;
|
int BLUE = 6;
|
||||||
@ -19,102 +23,113 @@ int brightness3 = 255;
|
|||||||
int brightness4 = 0;
|
int brightness4 = 0;
|
||||||
int brightness5 = 0;
|
int brightness5 = 0;
|
||||||
int brightness6 = 0;
|
int brightness6 = 0;
|
||||||
EthernetClient client;
|
|
||||||
|
EthernetClient client;
|
||||||
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD4, 0x22 };
|
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD4, 0x22 };
|
||||||
byte ip[] = { 192, 168, 1, 102 }; //ip arduino
|
byte ip[] = { 192, 168, 1, 102 }; //ip arduino
|
||||||
|
|
||||||
char server[] = "192.168.1.101"; //ip raspberry
|
char server[] = "192.168.1.101"; //ip raspberry
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
pinMode(WindSensorPin, INPUT);
|
pinMode(WindSensorPin, INPUT);
|
||||||
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
|
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
|
||||||
|
|
||||||
Serial.println("Rotations\tKm/h");
|
Serial.println("Rotations\tKm/h");
|
||||||
|
|
||||||
pinMode(led, OUTPUT);
|
pinMode(led, OUTPUT);
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
digitalWrite(led, LOW);
|
digitalWrite(led, LOW);
|
||||||
|
|
||||||
if (Ethernet.begin(mac) == 0) {
|
if (Ethernet.begin(mac) == 0)
|
||||||
|
{
|
||||||
Serial.println("Failed to configure Ethernet using DHCP");
|
Serial.println("Failed to configure Ethernet using DHCP");
|
||||||
for(;;)
|
for (;;)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.println("connecting...");
|
Serial.println("connecting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
//luxmetre
|
//luxmetre
|
||||||
delay(500);
|
delay(500);
|
||||||
duration = pulseIn(pin, HIGH);
|
duration = pulseIn(pin, HIGH);
|
||||||
T = 2*duration;
|
T = 2 * duration;
|
||||||
Serial.print("Luminosite (lux): ");
|
Serial.print("Luminosite (lux): ");
|
||||||
F = 1000000*1/T;
|
F = 1000000 * 1 / T;
|
||||||
Serial.println(F, DEC);
|
Serial.println(F, DEC);
|
||||||
if (F >= 1000)
|
if (F >= 1000)
|
||||||
{
|
{
|
||||||
digitalWrite(led, HIGH);
|
digitalWrite(led, HIGH);
|
||||||
analogWrite(RED, brightness4);
|
analogWrite(RED, brightness4);
|
||||||
analogWrite(GREEN, brightness5);
|
analogWrite(GREEN, brightness5);
|
||||||
analogWrite(BLUE, brightness6);
|
analogWrite(BLUE, brightness6);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
digitalWrite(led, LOW);
|
digitalWrite(led, LOW);
|
||||||
analogWrite(RED, brightness1);
|
analogWrite(RED, brightness1);
|
||||||
analogWrite(GREEN, brightness2);
|
analogWrite(GREEN, brightness2);
|
||||||
analogWrite(BLUE, brightness3);
|
analogWrite(BLUE, brightness3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.connect(server, 80)) {
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
client.print("GET /SLEGPI/ecriture.php?lux=");
|
client.print("GET /SLEGPI/ecriture.php?lux=");
|
||||||
client.print(F);
|
client.print(F);
|
||||||
client.println(" HTTP/1.1");
|
client.println(" HTTP/1.1");
|
||||||
client.println("Host: 192.168.1.101");
|
client.println("Host: 192.168.1.101");
|
||||||
//Serial.println(F);
|
//Serial.println(F);
|
||||||
Serial.println( "Connection: close" );
|
Serial.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
client.stop();
|
client.stop();
|
||||||
client.println();
|
client.println();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
//anémometre
|
//anémometre
|
||||||
Rotations = 0;
|
Rotations = 0;
|
||||||
sei();
|
sei();
|
||||||
delay (3000);
|
delay(3000);
|
||||||
cli();
|
cli();
|
||||||
WindSpeed = (Rotations * 0.75) * 1.609344;
|
WindSpeed = (Rotations * 0.75) * 1.609344;
|
||||||
Serial.print(Rotations); Serial.print("\t\t");
|
Serial.print(Rotations);
|
||||||
Serial.println(WindSpeed);
|
Serial.print("\t\t");
|
||||||
|
Serial.println(WindSpeed);
|
||||||
|
|
||||||
if (client.connect(server, 80)) {
|
if (client.connect(server, 80))
|
||||||
|
{
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
client.print("GET /SLEGPI/ecriture.php?vent=");
|
client.print("GET /SLEGPI/ecriture.php?vent=");
|
||||||
client.print(WindSpeed);
|
client.print(WindSpeed);
|
||||||
client.println(" HTTP/1.1");
|
client.println(" HTTP/1.1");
|
||||||
client.println("Host: 192.168.1.101");
|
client.println("Host: 192.168.1.101");
|
||||||
//Serial.println(F);
|
//Serial.println(F);
|
||||||
Serial.println( "Connection: close" );
|
Serial.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
client.stop();
|
client.stop();
|
||||||
client.println();
|
client.println();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void isr_rotation ()
|
||||||
|
{
|
||||||
|
if ((millis() - ContactBounceTime) > 15)
|
||||||
|
{ // debounce the switch contact.
|
||||||
|
Rotations++;
|
||||||
|
ContactBounceTime = millis();
|
||||||
}
|
}
|
||||||
void isr_rotation () {
|
|
||||||
|
|
||||||
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
|
|
||||||
Rotations++;
|
|
||||||
ContactBounceTime = millis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
|
unsigned long duration;
|
||||||
|
float T = 0;
|
||||||
|
|
||||||
int bLed = 3;
|
int bLed = 3;
|
||||||
int gLed = 4;
|
int gLed = 4;
|
||||||
int rLed = 6;
|
int rLed = 6;
|
||||||
int pin = 9;
|
int pin = 9;
|
||||||
unsigned long duration;
|
|
||||||
float T = 0;
|
|
||||||
int F = 1/T;
|
int F = 1/T;
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@ -15,28 +17,29 @@ void setup() {
|
|||||||
pinMode(rLed, OUTPUT);
|
pinMode(rLed, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
delay(1000);
|
delay(1000);
|
||||||
duration = pulseIn(pin, HIGH);
|
duration = pulseIn(pin, HIGH);
|
||||||
T = 2*duration;
|
T = 2 * duration;
|
||||||
Serial.print("F: ");
|
Serial.print("F: ");
|
||||||
F = 1000000*1/T;
|
F = 1000000 * 1 / T;
|
||||||
Serial.println(F, DEC);
|
Serial.println(F, DEC);
|
||||||
|
|
||||||
if (F<1000)
|
if (F < 1000)
|
||||||
{
|
{
|
||||||
digitalWrite(bLed, HIGH);
|
digitalWrite(bLed, HIGH);
|
||||||
digitalWrite(gLed, HIGH);
|
digitalWrite(gLed, HIGH);
|
||||||
digitalWrite(rLed, HIGH);
|
digitalWrite(rLed, HIGH);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (F>1000)
|
if (F > 1000)
|
||||||
{
|
{
|
||||||
digitalWrite(bLed, LOW);
|
digitalWrite(bLed, LOW);
|
||||||
digitalWrite(gLed, LOW);
|
digitalWrite(gLed, LOW);
|
||||||
digitalWrite(rLed, LOW);
|
digitalWrite(rLed, LOW);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user