sparkfun / SparkFun_Alphanumeric_Display_Arduino_Library

Arduino Library for the SparkX Qwiic Alphanumeric Display
Other
22 stars 12 forks source link

Temperature display #9

Closed DeStuiper closed 3 years ago

DeStuiper commented 3 years ago

Subject of the issue

Display temperature

Iam just not able to display the temperature given by a sensor in the right position so that the decimal dot position is correct: Like 25.6 is not displayed as 256. Simple as it should be Iam just not getting it. Maybe someone could give me a hint of what Iam missing (besides the according brains that is ;-) THX!

Your workbench

Steps to reproduce

include

include

include

SFE_ADS122C04 mySensor; HT16K33 display;

void setup(){ Serial.begin(115200); Serial.println("StartUp");

Wire.begin(); display.begin(); display.setBrightness(1); mySensor.begin(); mySensor.configureADCmode(ADS122C04_3WIRE_MODE);

display.print("MOIN"); delay(2500);

}

void loop() {

float temperature = mySensor.readPT100Centigrade();

Serial.print(F("The temperature is: ")); Serial.print(temperature); Serial.println(F("C"));

int n = (temperature)*100; // Increase temperature readout by two digits for LED display calculus

int t = (n % 10); // Get the third digit of the temperature readout int e = (n / 10) % 10; // Get the second digit of the temperature readout int m = (n / 100) % 10; // Get the first digit of the temperature readout int p = (n / 1000) % 10; // Get the first increment of the temperature readout

display.print(t, 0); display.print(e, 1); display.print(m, 2); display.printp, 3);

delay(500);
}

Expected behavior

Tell us what should happen See the correct temperature on the display

Actual behavior

I get some random blinking segments

fourstix commented 3 years ago

Hi, You are printing a number when you want to print a character. For example Zero is 48 decimal or 0x30 in Hex. So instead of printing the value 0, you really want to print the number value 48 for '0'.

Fortunately the ASCII characters for numbers are all in order. So you can change your code to define char t = '0' + n%10; char e = '0' + e = (n / 10) % 10; and so on to convert all your calculated number values into printable characters.

makin-stuff commented 3 years ago

Sorry @DeStuiper for the delay!

@fourstix is totally right! You need to call the printChar function with variables of type char. Try casting variables t, e, m, p to chars! Your code should look something like this:

// Convert to chars char t_char = t + '0'; char e_char = e + '0'; char m_char = m + '0'; char p_char = p + '0';

// Print chars to display display.printChar(t, 0); display.printChar(e, 1); display.printChar(m, 2); display.printChar(p, 3);

Also! Don't forget to turn on the decimal point if you need it! I'm going to close this issue, but re-open if this is not the solution you're looking for.