Update: my code is compiling now thanks to John Wasser, but the temperature is not displayed as I want: relative to the temperature. I have just posted my code at the bottom as post #8 Any help much appreciated!
Hi,
I am trying to display temperatures with the colour related to the temperature: red=hot, blue=cold. I have this working with another 2.2"display and the ILI9225 library with some help from this forum, I am not a great programmer.
I now want to do the same with a 1.8" screen for which I need the UCGLib library. The screen works fine but I am stuck with the "colour code".
For ILI I use:
void drawTempInColour(byte x, byte y,float temp,unsigned int colour)
{
char buf[16];
dtostrf(temp,6,1,buf);
tft.drawText(x, y, buf,colour);
}
which I changed into:
void drawTempInColour(byte x, byte y,float temp,unsigned int colour)
{
char buf[16];
dtostrf(temp,6,1,buf);
ucg.print(x, y, buf,colour);
}
for the UCG libs. I get the following error message from the Arduino IDE:
no matching function for call to 'Ucglib_ST7735_18x128x160_HWSPI::print(byte&, byte&, char [16], unsigned int&)'
I suspect that I need to add something to the line
Ucglib_ST7735_18x128x160_HWSPI ucg(/cd=/ 9 , /cs=/ 10, /reset=/ 8);
on top of the sketch but do not have the slightest clue what.
full sketch:
// Peter van de Pol, Wild Bill & many others :)
#include <SPI.h>
#include "Ucglib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);
// Data Sensors to Arduino pin 2
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/* Display wiring including resistors
1. RST >1KΩ> 8
2. CE >1KΩ> 10
3. D/C >1KΩ> 9
4. DIN >1KΩ> 11
5. Clk >1KΩ> 13
6. VCC +5V
7. BL >100Ω> +5V
8. GND GND
*/
void setup(void)
{
delay(1000);
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
//ucg.setFont(ucg_font_ncenR12_tr);
//ucg.setColor(255, 0, 0);
//ucg.setPrintPos(10,25);
//ucg.print("Starting 1-2-3");
ucg.clearScreen();
// Start up the Sensors library
sensors.begin();
// set the Sensor resolution to 9 bit - Valid values are 9, 10, or 11 bit.
sensors.setResolution(9);
delay(500);
}
void loop(void)
{
// put your main code here, to run repeatedly:
sensors.requestTemperatures(); // Get temperatures
// String sensor4 = String(sensors.getTempCByIndex(1),DEC); //DEC returns 10 decimals Change to 1 below
float temp1 = sensors.getTempCByIndex(0);
float temp2 = sensors.getTempCByIndex(1);
float temp3 = sensors.getTempCByIndex(2);
float temp4 = sensors.getTempCByIndex(3);
Serial.println(temp1);
Serial.println(temp2);
Serial.println(temp3);
Serial.println(temp4);
Serial.println( );
delay(100);
ucg.clearScreen();
ucg.setFont(ucg_font_helvB12_tr);
ucg.setColor(255, 255, 255);
ucg.setPrintPos(10,25);
ucg.print("Buffervat");
ucg.setFont(ucg_font_helvB10_tr);
ucg.setColor(0, 0, 145);
ucg.setPrintPos(5,60);
ucg.print("Boven");
ucg.setPrintPos(70,60);
ucg.print(temp1);
drawTempInColour(50, 60, temp1, GetColourForTemp(temp1));
ucg.setColor(20, 255, 20);
ucg.setPrintPos(5,80);
ucg.print("midden");
ucg.setPrintPos(70,80);
ucg.print(temp2);
ucg.setColor(20, 255, 20);
ucg.setPrintPos(5,100);
ucg.print("midden");
ucg.setPrintPos(70,100);
ucg.print(temp3);
ucg.setColor(20, 255, 20);
ucg.setPrintPos(5,120);
ucg.print("Onder");
ucg.setPrintPos(70,120);
ucg.print(temp4);
delay(500);
}
void drawTempInColour(byte x, byte y,float temp,unsigned int colour)
{
char buf[16];
dtostrf(temp,6,1,buf);
ucg.print(x, y, buf,colour);
}
unsigned int GetColourForTemp(float temp)
{
unsigned int Colour = 0, 0, 255; //dark blue
if (temp > 75)
{
Colour = 255, 0, 0; //red
}
else if (temp > 60)
{
Colour = 255, 140, 0; //dark orange
}
else if (temp > 40)
{
Colour = 255, 255, 0; //yellow
}
else if (temp > 30)
{
Colour = 65,105, 225; //royal blue
}
return Colour;
}
Can someone help me out here?
Thank you!
Peter