Fonctionnement
Le but de ce petit automate permet la gestion de la température, de l'éclairage et affichage d'alarmes de température.
Il est possible d'y ajouter quelques lignes pour le Ph par exemple mais le programme risque de ne plus tenir dans un UNO, il faudra passer par une méga.
Tous les paramètre sont configurables via un clavier analogique de 3 touches et l'affichage se fait sur un LCD 128X64 SPI.
Pour la mesure de température, j'ai opté pour une LM35 afin de ne pas surcharger le programme.
La température varie de +/- 0.5° ( précision de la sonde),l'alarme se déclenche a +/-2° par rapport a la consigne, exemple: si consigne = 20° alarme basse a 18° et alarme haute a 22°
L'écran prinipal
L'écran principal n'est pas encore terminé, il reste a faire la mise en page que je ferai dans la foulée
On y trouve une horloge analogique (un petit plus visuel lol)
La date
L'heure, la température
La programmation horaire
L'état du chauffage - marche - arrêt - alarme basse - alarme haute
La consigne de température (en cas de coupure de courant, celle-ci est configurée pour revenir a 20° et pas a 0°, cela permet de ne pas descendre trop bas en température)
Le menu de programmation
A chaque appui sur la touche menu, les réglages défileront de la manière suivante
- Le jour - Le mois - l'année - l'heure - les minutes - les secondes- heure de mise en marche - minutes de mise en marche - heure de mise a l' arrêt - minute de mise a l' arrêt - la consigne de température et l'enregistrement.
En cas de coupure de courant, les seuls paramètre enregistré sont la date et l'heure!!!
A noter: A partir du moment ou vous rentrer dans le menu de programmation, l'horloge s'arrête jusqu'à ce que vous sortez du menu!!!!!
Le programme
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX//
// //
// AUTOMATE POUR AQUARIUM //
// BY JOJO BRICOLO //
// Sonde LM35DZ //
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX//
#include <U8glib.h>
#include <Wire.h>
#include <Math.h>
#include <DS1307new.h>
U8GLIB_ST7920_128X64_4X u8g(2, 5, 4);
int angles,anglem,angleh,xs, ys, xm, ym, xh, yh;
float rad;
uint16_t startAddr = 0x0000;
uint16_t lastAddr;
uint16_t TimeIsSet = 0xaa55;
#define DDS_LOAD 12
#define DDS_CLOCK 3
#define DDS_DATA 2
#define Touche_PIN A0
int sensorPin = A0;
int sensorValue = 0;
int val_key;
int Select;
int Heure;
int Minute;
int Seconde;
int Jour;
int Mois;
int Annee;
int heurM = 0;
int minM = 0;
int heurA = 0;
int minA = 0;
int val1;
int val2;
int val3;
int val4;
int setTemp = 20;
int Chauff= 12;
int eclairage = 13;
int tempsensor =A1;
float ma_tempetf=0.0;
const uint8_t rook_bitmap[] PROGMEM = { // signe degré
0x10, // 00010000
0x28, // 00101000
0x28, // 00101000
0x10, // 00010000
0x00, // 00000000
0x00, // 00000000
0x00, // 00000000
0x00 // 00000000
};
void setup () {
pinMode(Chauff, OUTPUT); // Relai chauffage
pinMode (eclairage,OUTPUT); // Relai eclairage
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// RAM horloge
TimeIsSet = 0xffff;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.ctrl = 0x00;
RTC.setCTRL();
u8g.setFont(u8g_font_5x8); // ecriture de base
rad = ((2 * 3.1415926536) / 360);
}
////////////////////////// Fonctions Void
void Principal()
{
sensorValue = analogRead(sensorPin);
val_key = int(sensorValue/100);
if (Select == 0)
{
RTC.getTime();
Heure = RTC.hour;
Minute = RTC.minute;
Seconde = RTC.second;
Jour = RTC.day;
Mois = RTC.month;
Annee = RTC.year;
//Logo By mi
u8g.setFont(u8g_font_timB08);
u8g.drawStr( 50,60, " By Jojo Bricolo");
//////////////////////////////////// Affichage de l'Heure
u8g.setFont(u8g_font_timB08);
u8g.setPrintPos(56,18);
u8g.print(Heure);
u8g.drawStr( 68,18, "h");
if (Minute < 10){ u8g.drawStr( 74, 18, "0");
u8g.setPrintPos( 81, 18);
u8g.print(Minute);}
else
{u8g.setPrintPos( 76, 18);
u8g.print(Minute);}
u8g.drawStr( 90,17, "-");
////////// Affichage de la date
u8g.setFont(u8g_font_5x7);
{
u8g.setPrintPos(60,8);
u8g.print(Jour);
}
switch (RTC.month){
case 1:
u8g.drawStr( 69, 8, "Janv.");
break;
case 2:
u8g.drawStr( 71, 8, "fev.");
break;
case 3:
u8g.drawStr( 72, 8, " mars");
break;
case 4:
u8g.drawStr( 72, 8, " avr. ");
break;
case 5:
u8g.drawStr( 73, 8, " mai ");
break;
case 6:
u8g.drawStr( 72, 8, " juin ");
break;
case 7:
u8g.drawStr( 69, 8, "Juil.");
break;
case 8:
u8g.drawStr( 72, 8, " aout ");
break;
case 9:
u8g.drawStr( 69, 8, " sept.");
break;
case 10:
u8g.drawStr( 72, 8, "oct.");
break;
case 11:
u8g.drawStr( 72, 8, "nov.");
break;
case 12:
u8g.drawStr( 72, 8, "dec.");
break;
}
u8g.setPrintPos(96,8); //Année
u8g.print(Annee);
/////////////////////////////////////////// Temperature
int reading = analogRead(tempsensor);
float voltage = reading * 5.0 / 1024;
float ma_tempetf = voltage * 100 ;
/////////////////////////////////////// Affichage Temperature ////
u8g.setFont(u8g_font_timB08);
u8g.setPrintPos( 98, 18);
u8g.print(ma_tempetf);
u8g.drawBitmapP( 120, 11, 1, 8, rook_bitmap);
///////////////////////// Affichage consigne//////////////
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 64, 45,"Consigne");
u8g.setPrintPos( 111, 45);
u8g.print(setTemp);
u8g.drawBitmapP( 120, 39, 1, 8, rook_bitmap);
////////////// Commade chauffage
u8g.setFont(u8g_font_4x6);
if (ma_tempetf > setTemp)
{
digitalWrite(Chauff, LOW);
u8g.drawStr( 65, 37,"Chauff Arret");
}
if (ma_tempetf <= (setTemp-0.5))
{
digitalWrite(Chauff, HIGH);
u8g.drawStr( 65, 37,"Chauff Marche");
}
/////////////////////// Commande eclairage
val1 = (Heure*100)+Minute;
val2 = (heurM*100)+minM;
val3 = (heurA*100)+minA-1;
if ((val1 >= val2) && (val1 <= val3))
{
digitalWrite(eclairage, HIGH);
}
else
//if ((Heure >= heurA) && (Minute >= minA))
{
digitalWrite(eclairage, LOW);
}
////////////////////// Affichage consignes éclarage
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 56, 27,"Ecl");
u8g.setPrintPos( 71, 27);
u8g.print(heurM);
u8g.drawStr( 80, 27,"h");
u8g.setPrintPos( 85, 27);
u8g.print(minM);
//u8g.setFont(u8g_font_5x8);
u8g.drawStr( 96, 27,"a");
u8g.setPrintPos( 103, 27);
u8g.print(heurA);
u8g.drawStr( 113, 27,"h");
u8g.setPrintPos( 118, 27);
u8g.print(minA);
////////////////// Affichage alarme température
// u8g.setFont(u8g_font_4x6);
//if (ma_tempetf > (setTemp + 2))
//u8g.drawStr( 65, 37,"Temp Haute");
//else
// if (ma_tempetf < (setTemp - 2))
//u8g.drawStr( 65, 37,"Temp Basse");
//else
//u8g.drawStr( 65, 37," ");
}
/////////////////////////////// Horloge analogique
angles = (Seconde * 6)-90;
anglem = (Minute * 6)-90;
angleh = ((Heure * 30)-90) + ((anglem/12)+6);
Serial.println (angleh);
u8g.drawCircle(31,32,21);
u8g.drawCircle(31,32,19);
u8g.setFont(u8g_font_micro);
u8g.drawStr( 54, 35, "3");
u8g.drawStr( 30, 60, "6");
u8g.drawStr( 5, 35, "9");
u8g.drawStr( 28, 10, "12");
u8g.drawStr( 40, 16, "."); //1
u8g.drawStr( 47, 24, "."); //2
u8g.drawStr( 50, 33, "."); //3
u8g.drawStr( 47, 42, "."); //4
u8g.drawStr( 41, 50, "."); //5
u8g.drawStr( 31, 53, "."); //6
u8g.drawStr( 21, 50, "."); //7
u8g.drawStr( 14, 42, "."); //8
u8g.drawStr( 11, 33, "."); //9
u8g.drawStr( 14, 24, "."); //10
u8g.drawStr( 21, 16, "."); //11
u8g.drawStr( 31, 14, "."); //12
xs = 31 + (cos(angles * rad)*18);
ys = 32 + (sin(angles * rad)*18);
u8g.drawLine(31, 32, xs, ys);
xm = 31 + (cos(anglem * rad)*16);
ym = 32 + (sin(anglem * rad)*16);
u8g.drawLine(31, 32, xm, ym);
u8g.drawLine(32, 31, xm, ym);
xh = 31 + (cos(angleh * rad)*10);
yh = 32 + (sin(angleh * rad)*10);
u8g.drawLine(31, 32, xh, yh);
u8g.drawLine(32, 31, xh, yh);
////////////////////////////////////// Menu et règlages
if ((Select > 0) and (Select < 13))
{
u8g.drawStr(80,8,"REGLAGES");
if (Jour < 10)
{
u8g.drawStr( 73, 15, "0");
u8g.setPrintPos(77,15);
u8g.print(Jour);
}
else
{
u8g.setPrintPos(73,15);
u8g.print(Jour);
}
u8g.drawStr( 83,15, ":");
if (Mois < 10)
{
u8g.drawStr( 89, 15, "0");
u8g.setPrintPos( 94, 15);
u8g.print(Mois);
}
else
{
u8g.setPrintPos(89,15);
u8g.print(Mois);
}
u8g.drawStr( 100, 15, ":");
u8g.setPrintPos( 105, 15);
u8g.print(Annee);
//xxxxxxxxxxxxxxxxxxxx
if (Heure < 10)
{
u8g.drawStr( 78, 25, "0");
u8g.setPrintPos(82,25);
u8g.print(Heure);
}
else
{
u8g.setPrintPos(78,25);
u8g.print(Heure);
}
u8g.drawStr( 88,25, ":");
if (Minute < 10)
{
u8g.drawStr(93, 25, "0");
u8g.setPrintPos( 98, 25);
u8g.print(Minute);
}
else
{
u8g.setPrintPos( 93, 25);
u8g.print(Minute);
}
u8g.drawStr( 105, 25, ":");
if (Seconde < 10)
{
u8g.drawStr(110, 25, "0");
u8g.setPrintPos( 115, 25);
u8g.print(Seconde);
}
else
{
u8g.setPrintPos( 110, 25);
u8g.print(Seconde);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxx
u8g.drawStr(65,35,"Marche");
{
u8g.setPrintPos( 100, 35);
u8g.print(heurM);
}
u8g.drawStr( 110, 35, ":");
{
u8g.setPrintPos( 115, 35);
u8g.print(minM);
}
u8g.drawStr(65,45,"Arret");
{
u8g.setPrintPos( 100, 45);
u8g.print(heurA);
}
u8g.drawStr( 110, 45, ":");
{
u8g.setPrintPos( 115, 45);
u8g.print(minA);
}
u8g.drawStr(65,55,"Consigne");
{
u8g.setPrintPos( 105, 55);
u8g.print(setTemp);
}
u8g.drawBitmapP( 113, 50, 1, 8, rook_bitmap);
}
val_key = 0;
sensorValue = analogRead(sensorPin);
val_key = int(sensorValue/100);
////////////////////////////////////////////// Selection des reglages
switch (val_key)
{
case 7 :
{
Select = (Select + 1);
delay (200);
}
break;
}
if (Select == 1) u8g.drawStr(65,62," Reglage jour");
if (Select == 2) u8g.drawStr(65,62," Reglage mois");
if (Select == 3) u8g.drawStr(65,62," Reglage annee");
if (Select == 4) u8g.drawStr(65,62,"Reglage heures");
if (Select == 5) u8g.drawStr(65,62,"Reglage minutes");
if (Select == 6) u8g.drawStr(65,62,"Reglage Secondes");
if (Select == 7) u8g.drawStr(65,62,"Heure marche");
if (Select == 8) u8g.drawStr(65,62,"Minutes marche");
if (Select == 9) u8g.drawStr(65,62,"Heure arret");
if (Select == 10) u8g.drawStr(65,62,"Minutes arret");
if (Select == 11) u8g.drawStr(45,62, "Consigne temperature");
if (Select == 12) u8g.drawStr(65,62, "Enregistrer !");
if (Select == 13)
{
(Select = 0);
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// Entrée startAddr dans NV-RAM address 0x08
TimeIsSet = 0xffff;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
if (TimeIsSet != 0xaa55)
{
RTC.stopClock();
RTC.fillByYMD(Annee,Mois,Jour);
RTC.fillByHMS(Heure,Minute,Seconde);
RTC.setTime();
TimeIsSet = 0xaa55;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.startClock();
}
else
{
RTC.getTime();
}
}
//////////////// Touches +/-
switch (val_key)
{
case 3://-
{
delay (200);
if (Select == 1)
{
Jour = (Jour - 1);
}
if (Jour < 1)
{
(Jour = 31);
}
if (Select == 2)
{
Mois = (Mois - 1);
}
if (Mois < 1)
{
(Mois = 12);
}
if (Select == 3)
{
Annee = (Annee - 1);
}
if (Select == 4)
{
Heure = (Heure - 1);
}
if (Heure < 1)
{
(Heure = 23);
}
if (Select == 5)
{
Minute = (Minute - 1);
}
if (Minute < 1)
{(
Minute = 59);
}
if (Select == 6)
{
Seconde = (Seconde - 1);
}
if (Seconde < 1)
{
(Seconde = 59);
}
if (Select == 7)
{
heurM = (heurM - 1);
}
if (heurM < 1)
{
(heurM = 0);
}
if (heurM > 23)
{
(heurM = 0);
}
if (Select == 8)
{
minM = (minM - 1);
}
if (minM < 1)
{
(minM = 0);
}
if (minM >59)
{
(minM = 0);
}
if (Select == 9)
{
heurA = (heurA - 1);
}
if (heurA < 1)
{
(heurA = 0);
}
if (heurA> 23)
{
(heurA = 0);
}
if (Select == 10)
{
minA = (minA - 1);
}
if (minA < 1)
{
(minA = 0);
}
if (minA >59)
{
(minA = 0);
}
if (Select == 11)
{
setTemp = (setTemp - 1);
}
if (setTemp > 32)
{
(setTemp = 0);
}
}
break;
case 1: //+
{
delay (200);
if (Select == 1)
{
Jour = (Jour + 1);
}
if (Jour > 31)
{
(Jour = 1);
}
if (Select == 2)
{
Mois = (Mois + 1);
}
if (Mois > 12)
{
(Mois = 1);
}
if (Select == 3)
{
Annee = (Annee + 1);
}
if (Select == 4)
{
Heure = (Heure + 1);
}
if (Heure > 23)
{
(Heure = 0);
}
if (Select == 5)
{
Minute = (Minute + 1);
}
if (Minute > 59 )
{
(Minute = 0);
}
if (Select == 6)
{
Seconde = (Seconde + 1);
}
if (Seconde > 59)
{
(Seconde = 0);
}
if (Select == 7)
{
heurM = (heurM + 1);
}
if (heurM < 1)
{
(heurM = 0);
}
if (heurM> 23)
{
(heurM = 0);
}
if (Select == 8)
{
minM = (minM + 1);
}
if (minM < 1)
{
(minM = 0);
}
if (minM >59)
{
(minM = 0);
}
if (Select == 9)
{
heurA = (heurA + 1);
}
if (heurA < 1)
{
(heurA = 0);
}
if (heurA> 23){ (heurA = 0);}
if (Select == 10)
{
minA = (minA + 1);
}
if (minA < 1)
{
(minA = 0);
}
if (minA >59)
{
(minA = 0);
}
if (Select == 11)
{
setTemp = (setTemp + 1);
}
if (setTemp > 32)
{
(setTemp = 0);
}
}
break;
}
}
void loop()
{
u8g.firstPage();
do
Principal();
while( u8g.nextPage());
}
Modifications en cours!!
Ajout de deux touches supplémentaire pour le réglage de la consigne pour ne pas avoir a rentrer dans le menu de programmation.
Schéma de câblage en cours
Version finale
Les modifications:
- Ajout de deux boutons pour réglage de la consigne sans entrer dans le menu mais le paramétrage en mode programmation reste
- Consigne de température après coupure de courant 24° mini
- Consigne éclairage après coupure de courant 10h30 a 20h30
- Adjonction d'un relai d'alarme
Le programme final (mais peut être modifié si vous avez des idées a me soumettre)
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX//
// //
// AUTOMATE POUR AQUARIUM //
// BY JOJO BRICOLO //
// Sonde LM35DZ //
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX//
#include <U8glib.h>
#include <Wire.h>
#include <Math.h>
#include <DS1307new.h>
U8GLIB_ST7920_128X64_4X u8g(2, 5, 4);
int angles,anglem,angleh,xs, ys, xm, ym, xh, yh;
float rad;
uint16_t startAddr = 0x0000;
uint16_t lastAddr;
uint16_t TimeIsSet = 0xaa55;
//
#define DDS_LOAD 12
#define DDS_CLOCK 3
#define DDS_DATA 2
#define Touche_PIN A0
int sensorPin = A0;
int sensorValue = 0;
int val_key;
int Select;
int Heure;
int Minute;
int Seconde;
int Jour;
int Mois;
int Annee;
int heurM = 10;
int minM = 30;
int heurA = 20;
int minA = 30;
int val1;
int val2;
int val3;
int val4;
int setTemp = 24;
int Chauff = 11;
int eclairage = 12;
int alarme = 13;
int bplus = 5;
int bmoins = 6;
int tempsensor =A1;
float ma_tempetf=0.0;
const uint8_t rook_bitmap[] PROGMEM = { // signe degré
0x10, // 00010000
0x28, // 00101000
0x28, // 00101000
0x10, // 00010000
0x00, // 00000000
0x00, // 00000000
0x00, // 00000000
0x00 // 00000000
};
void setup () {
pinMode(Chauff, OUTPUT); // Relai chauffage
pinMode (eclairage,OUTPUT); // Relai eclairage
pinMode (alarme,OUTPUT); // Relai alarme
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// RAM horloge
TimeIsSet = 0xffff;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.ctrl = 0x00;
RTC.setCTRL();
u8g.setFont(u8g_font_5x8); // ecriture de base
rad = ((2 * 3.1415926536) / 360);
}
////////////////////////// Fonctions Void
void Principal()
{
sensorValue = analogRead(sensorPin);
val_key = int(sensorValue/100);
if (Select == 0)
{
RTC.getTime();
Heure = RTC.hour;
Minute = RTC.minute;
Seconde = RTC.second;
Jour = RTC.day;
Mois = RTC.month;
Annee = RTC.year;
//Logo By mi
u8g.setFont(u8g_font_timB08);
u8g.drawStr( 50,60, " By Jojo Bricolo");
//////////////////////////////////// Affichage de l'Heure
u8g.setFont(u8g_font_timB08);
u8g.setPrintPos(56,18);
u8g.print(Heure);
u8g.drawStr( 68,18, "h");
if (Minute < 10){ u8g.drawStr( 74, 18, "0");
u8g.setPrintPos( 81, 18);
u8g.print(Minute);}
else
{u8g.setPrintPos( 76, 18);
u8g.print(Minute);}
u8g.drawStr( 90,17, "-");
////////// Affichage de la date
u8g.setFont(u8g_font_5x7);
{
u8g.setPrintPos(60,8);
u8g.print(Jour);
}
switch (RTC.month){
case 1:
u8g.drawStr( 69, 8, "Janv.");
break;
case 2:
u8g.drawStr( 71, 8, "fev.");
break;
case 3:
u8g.drawStr( 72, 8, " mars");
break;
case 4:
u8g.drawStr( 72, 8, " avr. ");
break;
case 5:
u8g.drawStr( 73, 8, " mai ");
break;
case 6:
u8g.drawStr( 72, 8, " juin ");
break;
case 7:
u8g.drawStr( 69, 8, "Juil.");
break;
case 8:
u8g.drawStr( 72, 8, " aout ");
break;
case 9:
u8g.drawStr( 69, 8, " sept.");
break;
case 10:
u8g.drawStr( 72, 8, "oct.");
break;
case 11:
u8g.drawStr( 72, 8, "nov.");
break;
case 12:
u8g.drawStr( 72, 8, "dec.");
break;
}
u8g.setPrintPos(96,8); //Année
u8g.print(Annee);
/////////////////////////////////////////// Temperature
int reading = analogRead(tempsensor);
float voltage = reading * 5.0 / 1024;
float ma_tempetf = voltage * 100 ;
/////////////////////////////////////// Affichage Temperature ////
u8g.setFont(u8g_font_timB08);
u8g.setPrintPos( 98, 18);
u8g.print(ma_tempetf);
u8g.drawBitmapP( 120, 11, 1, 8, rook_bitmap);
//////////////////////////Commande consigne hors menu
if ((val_key == 0)&&(setTemp ) <=99)
{
(setTemp ++);
delay(100);
}
if ((setTemp)==32)
{
(setTemp=0);
}
if ((val_key == 5)&&(setTemp ) >=1)
{
(setTemp --);
delay(100);
}
///////////////////////// Affichage consigne///////////////////////////////////////////////////
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 64, 50,"Consigne");
u8g.setPrintPos( 111, 50);
u8g.print(setTemp);
u8g.drawBitmapP( 120, 44, 1, 8, rook_bitmap);
////////////// Commade chauffage
u8g.setFont(u8g_font_4x6);
if (ma_tempetf > setTemp)
{
digitalWrite(Chauff, LOW);
u8g.drawStr( 65, 35,"Chauff Arret");
}
if (ma_tempetf <= (setTemp-0.5))
{
digitalWrite(Chauff, HIGH);
u8g.drawStr( 65, 35,"Chauff Marche");
}
/////////////////////// Commande eclairage
val1 = (Heure*100)+Minute;
val2 = (heurM*100)+minM;
val3 = (heurA*100)+minA-1;
if ((val1 >= val2) && (val1 <= val3))
{
digitalWrite(eclairage, HIGH);
}
else
{
digitalWrite(eclairage, LOW);
}
////////////////////// Affichage consignes éclarage
u8g.setFont(u8g_font_4x6);
u8g.drawStr( 56, 26,"Ecl");
u8g.setPrintPos( 71, 26);
u8g.print(heurM);
u8g.drawStr( 80, 26,"h");
u8g.setPrintPos( 85, 26);
u8g.print(minM);
//u8g.setFont(u8g_font_5x8);
u8g.drawStr( 96, 26,"a");
u8g.setPrintPos( 103, 26);
u8g.print(heurA);
u8g.drawStr( 113, 26,"h");
u8g.setPrintPos( 118, 26);
u8g.print(minA);
////////////////// Affichage alarme température
u8g.setFont(u8g_font_4x6);
if (ma_tempetf > (setTemp + 2))
{
u8g.drawStr( 59, 43,"Temperature Haute");
digitalWrite (alarme,HIGH);
}
else
if (ma_tempetf < (setTemp - 2))
{
u8g.drawStr( 59, 43,"Temperature Basse");
digitalWrite (alarme,HIGH);
}
else
{
u8g.drawStr( 59, 43,"Temperature OK");
digitalWrite (alarme,LOW);
}
}
/////////////////////////////// Horloge analogique
angles = (Seconde * 6)-90;
anglem = (Minute * 6)-90;
angleh = ((Heure * 30)-90) + ((anglem/12)+6);
Serial.println (angleh);
u8g.drawCircle(31,32,21);
u8g.drawCircle(31,32,19);
u8g.setFont(u8g_font_micro);
u8g.drawStr( 54, 35, "3");
u8g.drawStr( 30, 60, "6");
u8g.drawStr( 5, 35, "9");
u8g.drawStr( 28, 10, "12");
u8g.drawStr( 40, 16, "."); //1
u8g.drawStr( 47, 24, "."); //2
u8g.drawStr( 50, 33, "."); //3
u8g.drawStr( 47, 42, "."); //4
u8g.drawStr( 41, 50, "."); //5
u8g.drawStr( 31, 53, "."); //6
u8g.drawStr( 21, 50, "."); //7
u8g.drawStr( 14, 42, "."); //8
u8g.drawStr( 11, 33, "."); //9
u8g.drawStr( 14, 24, "."); //10
u8g.drawStr( 21, 16, "."); //11
u8g.drawStr( 31, 14, "."); //12
xs = 31 + (cos(angles * rad)*18);
ys = 32 + (sin(angles * rad)*18);
u8g.drawLine(31, 32, xs, ys);
xm = 31 + (cos(anglem * rad)*16);
ym = 32 + (sin(anglem * rad)*16);
u8g.drawLine(31, 32, xm, ym);
u8g.drawLine(32, 31, xm, ym);
xh = 31 + (cos(angleh * rad)*10);
yh = 32 + (sin(angleh * rad)*10);
u8g.drawLine(31, 32, xh, yh);
u8g.drawLine(32, 31, xh, yh);
////////////////////////////////////// Menu et règlages
if ((Select > 0) and (Select < 13))
{
u8g.drawStr(80,8,"REGLAGES");
if (Jour < 10)
{
u8g.drawStr( 73, 15, "0");
u8g.setPrintPos(77,15);
u8g.print(Jour);
}
else
{
u8g.setPrintPos(73,15);
u8g.print(Jour);
}
u8g.drawStr( 83,15, ":");
if (Mois < 10)
{
u8g.drawStr( 89, 15, "0");
u8g.setPrintPos( 94, 15);
u8g.print(Mois);
}
else
{
u8g.setPrintPos(89,15);
u8g.print(Mois);
}
u8g.drawStr( 100, 15, ":");
u8g.setPrintPos( 105, 15);
u8g.print(Annee);
//xxxxxxxxxxxxxxxxxxxx
if (Heure < 10)
{
u8g.drawStr( 78, 25, "0");
u8g.setPrintPos(82,25);
u8g.print(Heure);
}
else
{
u8g.setPrintPos(78,25);
u8g.print(Heure);
}
u8g.drawStr( 88,25, ":");
if (Minute < 10)
{
u8g.drawStr(93, 25, "0");
u8g.setPrintPos( 98, 25);
u8g.print(Minute);
}
else
{
u8g.setPrintPos( 93, 25);
u8g.print(Minute);
}
u8g.drawStr( 105, 25, ":");
if (Seconde < 10)
{
u8g.drawStr(110, 25, "0");
u8g.setPrintPos( 115, 25);
u8g.print(Seconde);
}
else
{
u8g.setPrintPos( 110, 25);
u8g.print(Seconde);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxx
u8g.drawStr(65,35,"Marche");
{
u8g.setPrintPos( 100, 35);
u8g.print(heurM);
}
u8g.drawStr( 110, 35, ":");
{
u8g.setPrintPos( 115, 35);
u8g.print(minM);
}
u8g.drawStr(65,45,"Arret");
{
u8g.setPrintPos( 100, 45);
u8g.print(heurA);
}
u8g.drawStr( 110, 45, ":");
{
u8g.setPrintPos( 115, 45);
u8g.print(minA);
}
u8g.drawStr(65,55,"Consigne");
{
u8g.setPrintPos( 105, 55);
u8g.print(setTemp);
}
u8g.drawBitmapP( 113, 50, 1, 8, rook_bitmap);
}
val_key = 0;
sensorValue = analogRead(sensorPin);
val_key = int(sensorValue/100);
////////////////////////////////////////////// Selection des reglages
switch (val_key)
{
case 7 :
{
Select = (Select + 1);
delay (200);
}
break;
}
if (Select == 1) u8g.drawStr(65,62," Reglage jour");
if (Select == 2) u8g.drawStr(65,62," Reglage mois");
if (Select == 3) u8g.drawStr(65,62," Reglage annee");
if (Select == 4) u8g.drawStr(65,62,"Reglage heures");
if (Select == 5) u8g.drawStr(65,62,"Reglage minutes");
if (Select == 6) u8g.drawStr(65,62,"Reglage Secondes");
if (Select == 7) u8g.drawStr(65,62,"Heure marche");
if (Select == 8) u8g.drawStr(65,62,"Minutes marche");
if (Select == 9) u8g.drawStr(65,62,"Heure arret");
if (Select == 10) u8g.drawStr(65,62,"Minutes arret");
if (Select == 11) u8g.drawStr(45,62, "Consigne temperature");
if (Select == 12) u8g.drawStr(65,62, "Enregistrer !");
if (Select == 13)
{
(Select = 0);
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));// Entrée startAddr dans NV-RAM address 0x08
TimeIsSet = 0xffff;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
if (TimeIsSet != 0xaa55)
{
RTC.stopClock();
RTC.fillByYMD(Annee,Mois,Jour);
RTC.fillByHMS(Heure,Minute,Seconde);
RTC.setTime();
TimeIsSet = 0xaa55;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.startClock();
}
else
{
RTC.getTime();
}
}
//////////////// Touches +/-
switch (val_key)
{
case 3://-
{
delay (200);
if (Select == 1)
{
Jour = (Jour - 1);
}
if (Jour < 1)
{
(Jour = 31);
}
if (Select == 2)
{
Mois = (Mois - 1);
}
if (Mois < 1)
{
(Mois = 12);
}
if (Select == 3)
{
Annee = (Annee - 1);
}
if (Select == 4)
{
Heure = (Heure - 1);
}
if (Heure < 1)
{
(Heure = 23);
}
if (Select == 5)
{
Minute = (Minute - 1);
}
if (Minute < 1)
{(
Minute = 59);
}
if (Select == 6)
{
Seconde = (Seconde - 1);
}
if (Seconde < 1)
{
(Seconde = 59);
}
if (Select == 7)
{
heurM = (heurM - 1);
}
if (heurM < 1)
{
(heurM = 0);
}
if (heurM > 23)
{
(heurM = 0);
}
if (Select == 8)
{
minM = (minM - 1);
}
if (minM < 1)
{
(minM = 0);
}
if (minM >59)
{
(minM = 0);
}
if (Select == 9)
{
heurA = (heurA - 1);
}
if (heurA < 1)
{
(heurA = 0);
}
if (heurA> 23)
{
(heurA = 0);
}
if (Select == 10)
{
minA = (minA - 1);
}
if (minA < 1)
{
(minA = 0);
}
if (minA >59)
{
(minA = 0);
}
if (Select == 11)
{
setTemp = (setTemp - 1);
}
if (setTemp > 32)
{
(setTemp = 0);
}
}
break;
case 1: //+
{
delay (200);
if (Select == 1)
{
Jour = (Jour + 1);
}
if (Jour > 31)
{
(Jour = 1);
}
if (Select == 2)
{
Mois = (Mois + 1);
}
if (Mois > 12)
{
(Mois = 1);
}
if (Select == 3)
{
Annee = (Annee + 1);
}
if (Select == 4)
{
Heure = (Heure + 1);
}
if (Heure > 23)
{
(Heure = 0);
}
if (Select == 5)
{
Minute = (Minute + 1);
}
if (Minute > 59 )
{
(Minute = 0);
}
if (Select == 6)
{
Seconde = (Seconde + 1);
}
if (Seconde > 59)
{
(Seconde = 0);
}
if (Select == 7)
{
heurM = (heurM + 1);
}
if (heurM < 1)
{
(heurM = 0);
}
if (heurM> 23)
{
(heurM = 0);
}
if (Select == 8)
{
minM = (minM + 1);
}
if (minM < 1)
{
(minM = 0);
}
if (minM >59)
{
(minM = 0);
}
if (Select == 9)
{
heurA = (heurA + 1);
}
if (heurA < 1)
{
(heurA = 0);
}
if (heurA> 23){ (heurA = 0);}
if (Select == 10)
{
minA = (minA + 1);
}
if (minA < 1)
{
(minA = 0);
}
if (minA >59)
{
(minA = 0);
}
if (Select == 11)
{
setTemp = (setTemp + 1);
}
if (setTemp > 32)
{
(setTemp = 0);
}
}
break;
}
}
void loop()
{
u8g.firstPage();
do
Principal();
while( u8g.nextPage());
}
Le schéma
Le câblage du clavier
Schéma trouvé sur le net!