Skip to content
Snippets Groups Projects
Commit 4b777d02 authored by Puissegur Alexis's avatar Puissegur Alexis
Browse files
parents fc08b2a4 3717fc19
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,11 @@
#include "Bluetooth.h"
#include "Son.h"
#include "Potentiometer.h"
#include "MotionSensor.h"
#define SPAN 3000
#define HEADER_LIGHT_ON "LIGHT"
#define HEADER_SOUND_ON "SOUND"
#define HEADER_PLANT_OK "STOP"
#define REMAINING_TIME 300000 // 5MIN
#define DATASPAN 10000 // 5MIN
#define ALARMSPAN 10000 // 10SEC
......@@ -40,6 +42,7 @@ Luminosite luminosite;
Potentiometer pot;
Son buzzer;
Bluetooth bluetooth;
MotionSensor motion;
int humi;
int lumi;
......@@ -49,6 +52,7 @@ int dataTimeStamp;
unsigned long timeStamp;
boolean ledHasBeenTurnedOn;
boolean alarmHasBeenTurnedOn;
boolean plantInNeed;
unsigned long timePushed;
unsigned long alarmTimeStamp;
unsigned long lightTimeStamp;
......@@ -63,7 +67,11 @@ void updateSensors(){
void display(){
monEcran1.setContrast(70, false);
updateSensors();
monEcran1.printMsg("CRYING PLANT !",0);
if(plantInNeed){
monEcran1.printMsg("CRYING PLANT !",0);
} else {
monEcran1.printMsg("PLANT IS OK !",0);
}
monEcran1.printMsg(((String)"TEMP : ") + temp,2);
monEcran1.printMsg(((String)"HUMI : ") + humi,3);
monEcran1.printMsg(((String)"LUMI : ") + lumi,4);
......@@ -96,9 +104,13 @@ void receiveFromBluetooth() {
monEcran1.printMsg(buffer,0);
if (buffer.startsWith(HEADER_LIGHT_ON)){
dealWithLight();
plantInNeed = true;
}
else if (buffer.startsWith(HEADER_SOUND_ON)){
dealWithSound();
plantInNeed = true;
} else if(buffer.startsWith(HEADER_PLANT_OK)) {
plantInNeed = false;
}
}
......@@ -132,6 +144,7 @@ void setup()
timeStamp = 0;
ledHasBeenTurnedOn = false;
alarmHasBeenTurnedOn = false;
plantInNeed = false;
timePushed = 0;
alarmTimeStamp = 0;
dataTimeStamp = 0;
......@@ -180,7 +193,12 @@ if(millis() - timePushed < REMAINING_TIME){
ledHasBeenTurnedOn = false;
maLed1.eteint();
}
}
}
if(plantInNeed && motion.detectsStartOfMotion()){
dealWithSound();
dealWithLight();
}
}
#include "Bouton.h"
#include "Led.h"
#include "Meteo.h"
#include "Screen.h"
#include "Luminosite.h"
#include "Bluetooth.h"
#include "Son.h"
#define SPAN 3000
#define HEADER_LIGHT_ON "LIGHT"
#define HEADER_SOUND_ON "SOUND"
#define REMAINING_TIME 10000
#define FAb4 740
#define LAb4 932
/*
Thingz prend ses mesures et envoie les donnes l'appli java (toutes les 5mins par ex)
l'appli java est une IHM configurable qui :
affiche les donnes en temps rel sur des graphiques
sait s'il faut arroser la plante ou non
envoie un mail au prof si besoin pour arroser
envoie via bluetooth si arrosage possible ou urgent et si en semaine ou weekend
son plus ou moins long
Messages bluetooth :
LIGHT;
SOUND;WEEKEND
SOUND;SEMAINE
*/
Bouton monBouton1;
Led maLed1;
Meteo meteo;
Screen monEcran1;
Bluetooth bluetooth;
Luminosite luminosite;
Son buzzer;
int humi;
int lumi;
int temp;
unsigned long timeStamp;
boolean ledHasToBeTurnedOn;
unsigned long timePushed;
unsigned long alarmTimeStamp;
void setup()
{
temp = 0;
lumi = 0;
humi = 0;
timeStamp = 0;
ledHasToBeTurnedOn = false;
timePushed = 0;
alarmTimeStamp = 0;
}
void updateSensors(){
temp = meteo.temperature();
lumi = luminosite.etat();
humi = meteo.getHumidity();
}
void display(){
monEcran1.setContrast(70, false);
updateSensors();
monEcran1.printMsg("CRYING PLANT !",0);
monEcran1.printMsg(((String)"TEMP : ") + temp,2);
monEcran1.printMsg(((String)"HUMI : ") + humi,3);
monEcran1.printMsg(((String)"LUMI : ") + lumi,4);
}
void sendBluetoothDataToServer(){
}
void dealWithSound(String data){
if(0){ // on weekend then water
} else { // on weekday then trigger the alarm for 5min
alarmTimeStamp = millis();
}
}
void receiveFromBluetooth() {
String buffer;
if (bluetooth.dataAvailable()){
buffer = bluetooth.receive();
}
if (buffer.startsWith(HEADER_LIGHT_ON)){
// DO NOTHING YET
}
else if (buffer.startsWith(HEADER_SOUND_ON)){
dealWithSound(buffer); // change
}
}
void fireAlarm(){
buzzer.tone(FAb4,600);
buzzer.tone(LAb4,200);
}
void loop()
{
if(millis() - timePushed < REMAINING_TIME){
if(millis() - timeStamp > SPAN){
timeStamp = millis();
display();
}
} else {
monEcran1.clear();
monEcran1.setContrast(0, false);
}
if (monBouton1.estTenuAppuye()) {
timePushed = millis();
maLed1.inverse();
}
if(millis() - alarmTimeStamp < REMAINING_TIME && millis() > REMAINING_TIME){
fireAlarm();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment