Dallas temp on 8 x 16 matrix

Good morning,,
My problem is with not displaying negative temperature correctly. Normal plus temps are correct, but when the temp goes negative the negative bar flashes behind the normal digit rather than in front of it.
The code I am using:

#include<Wire.h>
#include <MD_Parola.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 2
#define CS_PIN 11
#define DATA_PIN 12
#define CLK_PIN 10
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
int val1 = 20;
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
myDisplay.begin();
myDisplay.setIntensity(3);
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print("OUT");
myDisplay.setPause(1000);
myDisplay.setSpeed(1000);
delay(3000);
myDisplay.displayClear();
}
void loop() {
sensors.requestTemperatures();
int temp1 = (sensors.getTempCByIndex(0));
myDisplay.print(temp1);
delay(1000);

}
Can anyone kindly suggest a remedy, I have tried all I can find but to no avail.
Many thanks.

Why are you using integers for the temperature? DS18b20 sensors return a float.

Normal plus temps are correct, but when the temp goes negative the negative bar flashes behind the normal digit rather than in front of it.

Does that mean the minus sign isn't in front of the digits? Let me guess, the minus sign isn't displayed at all if the number has two digits.
If I'm right, a float will be displayed completely wrong. That's because the MD_Parola library implements the write() method incorrectly. It draws the string provided but don't move the text insertion position forward. The Print base class heavily depends on that so it shouldn't use it if it doesn't fulfill the requirements. You might convert the number to a c-string before printing it because printing it (using write()) as printing complete strings seems to be implemented correctly.

PyrusBoy:
Good morning,,
My problem is with not displaying negative temperature correctly that even after having 62 posts on this forum I still have not read the instructions on how to properly post code using CODE TAGS.

Morning gfvalvo,
It is difficult to teach an old dog new tricks. At 77 years old, and still writing and constructing games for the grandkids to keep them amused during lock down. I do tend to do things in the best logical solution for me. It is fine for young wizz kids to adhere strictly to new methods but our minds have proved more difficult to comprehend every complication presented and criticised for being old.

I would have expected someone of such maturity to accept valid criticism with more grace. Use of code tags is nothing new or wizzy, it shows respect to those from whom you would like help, and is a forum rule.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.