greiman / SSD1306Ascii

Text only Arduino Library for SSD1306 OLED displays
MIT License
490 stars 120 forks source link

degrees celsius symbol #91

Closed musapinar closed 1 year ago

musapinar commented 2 years ago

Hello,

How do I print code 167 of cp437? https://www.ascii-codes.com/ It refers to the "degrees Celsius" symbol. I'm using System5x7. I tried to include the cp437 header file from the fonts directory and then print it like oled.print(167) but no joy. It prints 167 as an integer.

Thank you for your help.

greiman commented 2 years ago

The degree symbol is the last character in the System5x7 font it is character 128 decimal or 200 octal.

This code:

  oled.setFont(System5x7);
  auto tempC = 25.0;
  auto tempF = tempC*9/5 + 32;
  oled.print(tempC, 1);  // Use one decimal digit
  oled.print(" \200C is ");  // \200 is octal escape for degree symbol
  oled.print(tempF, 1);
  oled.println(" \200F\n");

Should print:

25.0 °C is 77.0 °F

musapinar commented 2 years ago

That did work. Thank you Bill. I can see it's been documented since 2018 here : https://github.com/greiman/SSD1306Ascii/blob/master/src/fonts/System5x7.h#L144 It did not came up in the search results within the repo when I looked for "degrees". Sorry about that. Have a great day.

greiman commented 2 years ago

If you need symbols in cp437 you can use cp437font8x8 or Adafruit5x7. For Adafruit5x7 you must change this symbol in Adafruit5x7.h.

#define ADAFRUIT_ASCII96 0 // was one

To select the fonts use: oled.setFont(cp437font8x8); or oled.setFont(Adafruit5x7);

The down side is that println() will no longer work since \n and \r are now this bullet, ◙, and eighth note, ♪.

You must use cursor positioning and clear line instead of println().

Also you must use escaped character codes.