Hi,
Thanks for the quick reply. I started to work today on the code and just realized that graphic.print() doesn't handle float numbers. I'm reading the value from DS18B20. Finally I multiplied the temperature reading and put into an array digit by digit, and put the decimal point while printing out the digits separately. Than I had to solve the positioning issues, to keep the value at the same place regardless how many digits were printed, I dealt with the minus sign also. It was hard work, the code a bit complicated, there must be a more elegant was to do this, but I'm happy with it. Sorry if it isn't formatted and commented well, I'm new to programming.
I would like to add a button to navigate through different pages, with an interrupt to increment the "item" variable of switch case. To erase the previous page I draw a white box before printing the new data. This makes a little slow to navigate through the pages, I will try to erase the rows with "spaces" only.
Is there any way to send custom bitmaps to the display? I mean a snowflake for example when the temperature is below freezing.
switch(item)
{
case 1:
graphic.setCoordinate(5,5);
graphic.print("case 1");
sensors.requestTemperatures(); // Send the command to get temperatures
temp= (int)(sensors.getTempCByIndex(0)*10);
sprintf(array, "%i", temp);
if (temp>=0 && temp<10) {
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(" ");
temp_pos +=12*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print("0.");
temp_pos += 12*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[0]);
temp_pos=temp_posX;
}
if (temp>=10 && temp<100) {
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(" ");
temp_pos += 12*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[0]);
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(".");
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[1]);
temp_pos=temp_posX;
}
if (temp>=100)
{
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(" ");
temp_pos += 6*size_factor;
for (int a=0; a<=1;a++){
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[a]);
temp_pos += 6*size_factor;
}
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(".");
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[2]);
temp_pos=temp_posX;
}
if (temp<0 && temp>-10)
{
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(" ");
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[0]);
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print("0.");
temp_pos += 12*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[1]);
temp_pos=temp_posX;
}
if (temp<-10 && temp>-100)
{
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(" ");
temp_pos+=6;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[0]);
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[1]);
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(".");
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[2]);
temp_pos=temp_posX;
}
if (temp<=-100)
{
for (int a=0; a<=2;a++){
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[a]);
temp_pos += 6*size_factor;
}
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(".");
temp_pos += 6*size_factor;
graphic.setCoordinate(temp_pos,temp_posY);
graphic.print(array[3]);
temp_pos=temp_posX;
}