Bonjour, j'ai bidouillé le code suivant :
/******************* Librairie ***********/
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>
#include <avr/sleep.h>
#include <OneWire.h>
#include <VirtualWire.h>
/****************** Fin librairie ********/
/*************** Définition des pins ****/
#define SD_CS 4 // Pin pour la carte SD
#define TFT_CS 10 // Pin pour l'affichage TFT
#define TFT_DC 8 // Pin pour les commandes TFT
#define TFT_RST -1 //Pin du reset (Ou connecté au +5V)
#define trigPin A3
#define echoPin 5
/********** Fin définition des pins ****/
/******** Définition des boutons + couleurs + variables *****/
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BUTTON_NONE 0
#define BUTTON_DOWN 1
#define BUTTON_RIGHT 2
#define BUTTON_SELECT 3
#define BUTTON_UP 4
#define BUTTON_LEFT 5
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
int count = 0 ;
int thisByte = 33;
int DS18S20_Pin = 7;
OneWire ds(DS18S20_Pin);
File Temp;
/******************* Fin Définition des boutons + couleurs + variables **************************/
/************************* Capture de température INTERNE ***********************************/
float getTemp(){
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
/************************ Fin de capture de température INTERNE **********************************/
/************************ Setup *********************************/
void setup(void)
{
Serial.begin(9600);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
/*************** Sauvegarde sur SD ************************************/
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
Temp = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (Temp) {
Serial.print("Writing to test.txt...");
Temp.println("Temperature interne :");
Temp.print(getTemp);
Temp.flush();
Temp.close();
Serial.println("done.");
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
Temp = SD.open("test.txt");
if (Temp) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (Temp.available()) {
Serial.write(Temp.read());
}
// close the file:
Temp.close();
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
/*************** Fin sauvegarde sur SD ************************************/
tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab
// If your TFT's plastic wrap has a Green Tab, use the following:
//tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab
Serial.println("OK!");
tft.fillScreen(0x0000);
tft.setRotation(1);
}
/************************ Fin Setup *********************************/
/************************ Partie écran *********************************/
uint8_t readButton(void)
{
float a = analogRead(3);
a *= 5.0;
a /= 1024.0;
Serial.print("Button read analog = ");
Serial.println(a);
if (a < 0.2) return BUTTON_DOWN;
if (a < 1.0) return BUTTON_RIGHT;
if (a < 1.5) return BUTTON_SELECT;
if (a < 2.0) return BUTTON_UP;
if (a < 3.2) return BUTTON_LEFT;
else return BUTTON_NONE;
}
uint8_t buttonhistory = 0;
void loop()
{
count++;
/****************** Envoie par FM ****************/
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *) &getTemp, sizeof(int));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
/**************** Fin envoie par FM *************/
uint8_t b = readButton();
tft.setTextSize(2);
if (buttonhistory == 0)
{
tft.setTextColor(ST7735_GREEN);
tft.setCursor(0, 0);
tft.print (" CHALET\n ISOLE");
tft.setTextColor(ST7735_RED);
tft.setCursor(0, 60);
tft.print (" Bonjour,\n Appuyez \n pour \n demarrer");
while(b != BUTTON_SELECT) b = readButton();
buttonhistory |= 0;
delay (1000);
tft.fillScreen(BLACK);
tft.setTextColor(ST7735_RED);
tft.setCursor(0, 0);
tft.print ("T interne :-> \n");
tft.print ("T externe : \n");
tft.print ("Niv d'eau : \n");
tft.print ("Veille : <- \n");
buttonhistory |= 1;
}
if (b == BUTTON_DOWN)
{
tft.fillScreen(BLACK);
tft.setTextColor(ST7735_RED);
tft.setCursor(0, 10);
tft.print("T Int =\n ");
tft.print (getTemp());
tft.print ("\xf7 C");
buttonhistory |= 2;
}
if (b == BUTTON_LEFT)
{
tft.fillScreen(BLACK);
tft.setTextColor(ST7735_YELLOW);
tft.setCursor(0, 60);
tft.print("T Ext =\n");
tft.print (getTemp());
tft.print ("\xf7 C");
buttonhistory |= 3;
}
if (b == BUTTON_RIGHT)
{
tft.fillScreen(BLACK);
tft.setTextColor(ST7735_GREEN);
tft.setCursor(0, 110);
tft.print("Niv Eau = ");
tft.print(count);
tft.print ("%");
buttonhistory |= 4;
}
/************************ Mode veille (à optimiser..) *****************************/
if (b == BUTTON_UP)
{
tft.setTextColor(ST7735_WHITE);
tft.fillScreen(BLACK);
tft.setCursor(0, 10);
tft.print("Mode veille"); // Message de mis en sommeil
delay (2000);
tft.fillScreen(BLACK);
delay(100);
set_sleep_mode(SLEEP_MODE_IDLE); //Définition du mode sommeil
sleep_mode(); // Activation du mode veille
count = 0;
}
if (b == BUTTON_SELECT)
{
sleep_mode();
sleep_disable ();
tft.print ("Sortie");
tft.fillScreen(BLACK);
tft.setTextColor(ST7735_RED);
tft.setCursor(0, 0);
tft.print ("T interne : D \n");
tft.print ("T externe : B\n");
tft.print ("Niv d'eau : H\n");
tft.print ("Veille : G\n");
buttonhistory |= 5;
}
/************************ fin Mode veille *****************************/
/************************ Fin partie écran *****************************/
}
Je dis bidouiller car c'est pas super bien organiser je l'avoue...
Bref, le soucis, quand je vérifie si il y a des erreurs, j'ai comme message : Ecran:131: error: call of overloaded 'print(float (&)())' is ambiguous
Le problème vient donc d'ici : Temp.print(getTemp);
Je ne comprends pas.. Quand je met le code a part pour la sauvegarde sur SD, avec une variable getTemp en float, je n'ai pas ce message d'erreur.. Une idée ?
SUITE AU POST SUIVANT CAR PLUS DE PLACE..