Bonjour, j'ai fait un programme qui a pour but d'afficher l'heure et une luminosité et une température capté sur une delle tactile.
Pour réussir à afficher l'heure, j'ai utilisé une fonction itoa(). Cependant quand j'utilise cette fonction ma température n'est plus stable (elle affiche toujours la bonne température mais affiche parfois des nombre hasardeux).
Voici le programme que j'utilise:
#include <ezLCDLib.h>
#include <Wire.h> //BH1750 I2C Mode (inclure des bibliothéques externe)
#include <math.h>
#include <DS1307new.h>
ezLCD3 lcd;
int touch = 0;
int clear;
int option15 = 14;
int digits15 = 2;
int dp15 = 0;
int val;
int val2;
int lol;
int lol2;
int BH1750address = 0x23;
byte buff[2];
int xPos6 = 90;
int yPos6 = 35;
int xPos7 = 90;
int yPos7 = 100;
int digits7 = 3;
int width6 = 60;
int height6 = 30;
uint16_t startAddr = 0x0000;
uint16_t lastAddr;
uint16_t TimeIsSet = 0xaa55;
void setup() {
Wire.begin();
pinMode(2, INPUT);
digitalWrite(2, HIGH);
RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));
TimeIsSet = 0xffff;
//RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
//RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
if (TimeIsSet != 0xaa55)
{
RTC.stopClock();
//RTC.fillByYMD(2014,5,19);
//RTC.fillByHMS(8,44,00);
RTC.setTime();
TimeIsSet = 0xaa55;
RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
RTC.startClock();
}
else
{
RTC.getTime();
}
RTC.ctrl = 0x00;
RTC.setCTRL();
uint8_t MESZ;
MESZ = RTC.isMEZSummerTime();
accueil();
}
void loop () {
touch=lcd.wstack(0);
lol = (RTC.minute - 1) ;
RTC.getTime();
char heures[2];
char minutes[2];
analogRead(RTC.hour);
analogRead(RTC.minute);
analogRead(RTC.second);
if (RTC.hour < 10)
{
lcd.xy(260,1);
lcd.color(WHITE);
lcd.println("0");
lcd.xy(270,1);
lcd.color(WHITE);
lcd.println("9");
if(RTC.second <= 59){
lcd.xy(270,1);
lcd.color(WHITE);
lcd.println(lol2);
}
lcd.xy(260,1);
lcd.color(BLACK);
lcd.println("0");
lcd.xy(270,1);
lcd.color(BLACK);
lcd.printString(itoa(RTC.hour,heures,DEC));
}
else{
lcd.xy(260,1);
lcd.color(WHITE);
lcd.println("0");
lcd.xy(270,1);
lcd.color(WHITE);
lcd.println("9");
lcd.xy(260,1);
lcd.color(BLACK);
lcd.printString(itoa(RTC.hour,heures,DEC));
}
lcd.xy(285,1);
lcd.color(BLACK);
lcd.println(":");
if (RTC.minute < 10)
{
lcd.xy(290,1);
lcd.color(WHITE);
lcd.println("0");
lcd.xy(300,1);
lcd.color(WHITE);
lcd.println("9");
if(RTC.second <= 59){
lcd.xy(300,1);
lcd.color(WHITE);
lcd.println(lol);
}
lcd.xy(290,1);
lcd.color(BLACK);
lcd.println("0");
lcd.xy(300,1);
lcd.color(BLACK);
lcd.printString(itoa(RTC.minute,minutes,DEC));
if (RTC.minute >= 59 && RTC.second >=59){
lcd.xy(260,1);
lcd.color(WHITE);
lcd.printString(itoa(RTC.hour,heures,DEC));
}
}
else{
lcd.xy(290,1);
lcd.color(WHITE);
lcd.println("0");
lcd.xy(300,1);
lcd.color(WHITE);
lcd.println("9");
lcd.xy(293,1);
lcd.color(BLACK);
lcd.printString(itoa(RTC.minute,minutes,DEC));
if(RTC.second >= 59){
lcd.xy(293,1);
lcd.color(WHITE);
lcd.printString(itoa(RTC.minute,minutes,DEC));
}
if (RTC.minute >= 59 && RTC.second >=59){
lcd.xy(260,1);
lcd.color(WHITE);
lcd.printString(itoa(RTC.hour,heures,DEC));
}
}
lcd.theme( 1, 0, 3, 0, 2, 3, 2, 2, 2, 1, 1 );
uint8_t MESZ = RTC.isMEZSummerTime();
RTC.getRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
lastAddr = lastAddr + 1;
RTC.setRAM(0, (uint8_t *)&lastAddr, sizeof(uint16_t));
RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
val2 = analogRead(tempPin);
dat= (500 * val2) / 1024;
int i;
BH1750_Init(BH1750address);
if(2==BH1750_Read(BH1750address))
{
val=((buff[0]<<8)|buff[1])/1.2;
}
delay(150);
lcd.wvalue(6, dat);
lcd.wvalue(7, val);
}
void accueil(void) {
lcd.begin( EZM_BAUD_RATE );
lcd.cls( WHITE, BLACK );
lcd.font("0");
lcd.digitalMeter( 6, xPos6, yPos6, width6, height6, option15, dat, digits15, dp15, 4);
lcd.theme( 4, 155, 152, 3, 130, 0, 0, 1, 147, 153, 1 );
lcd.digitalMeter( 7, xPos7, yPos7, width6, height6, option15, val, digits7, dp15, 5);
lcd.theme( 5, 155, 152, 3, 130, 0, 0, 1, 147, 153, 1 );
}
int BH1750_Read(int address)
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available())
{
buff[i] = Wire.read();
i++;
}
Wire.endTransmission();
return i;
}
void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);
Wire.endTransmission();
}
Je serais vraiment reconnaissant à la personne qui pourra m'aider.