/*************************************************** This is an example for the Adafruit Thermocouple Sensor w/MAX31855K Designed specifically to work with the Adafruit Thermocouple Sensor ----> https://www.adafruit.com/products/269 These displays use SPI to communicate, 3 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ #include "Adafruit_MAX31855.h" #include "Adafruit_LEDBackpack.h" #include "Adafruit_GFX.h" #include Adafruit_7segment matrix = Adafruit_7segment(); int thermoDO = 4; int thermoCS = 6; int thermoCLK = 7; Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO); void setup() { Serial.begin(9600); // Start up the library for 7-seg and set max brightness matrix.begin(0x70); matrix.setBrightness(15); matrix.writeDisplay(); // wait for MAX chip to stabilize delay(1000); } void loop() { int c = thermocouple.readCelsius(); if (isnan(c)) { Serial.println("Something wrong with thermocouple!"); } else { String t = String(abs(c)); Serial.println(t); if ((t.length() == 4) && (c>0)) { // If the temerature is between 999 and 9999 (actually, the highest temperature could be 1400) String t1 = t.substring(0, 1); // ...we need the first String t2 = t.substring(1, 2); // and second String t3 = t.substring(2, 3); // and third digit String t4 = t.substring(3, 4); // and fourth digit matrix.writeDigitNum(0, t1.toInt()); // which we plot to the first, second, third and fourth place of 7-seg matrix.writeDigitNum(1, t2.toInt()); matrix.writeDigitNum(3, t3.toInt()); matrix.writeDigitNum(4, t4.toInt()); } ; if ((t.length() == 3) && (c>0)) { // If the temerature is between 100 and 999 String t1 = t.substring(0, 1); // ...we need the first String t2 = t.substring(1, 2); // and second String t3 = t.substring(2, 3); // and third digit matrix.writeDigitNum(0, t1.toInt()); // which we plot to the first, second and third place of 7-seg matrix.writeDigitNum(1, t2.toInt()); matrix.writeDigitNum(3, t3.toInt()); } ; if ((t.length() == 3) && (c<0)) { // If the temerature is between -99 and -999 (actually, the lowest temperature could be -200) String t1 = t.substring(0, 1); // ...we need the first String t2 = t.substring(1, 2); // and second String t3 = t.substring(2, 3); // and third digit matrix.writeDigitNum(1, t1.toInt()); // which we plot to the second, third and fourth place of 7-seg matrix.writeDigitNum(3, t2.toInt()); matrix.writeDigitNum(4, t3.toInt()); matrix.writeDigitRaw(0,64); // and we plot the minus sign to first place. } ; if (t.length() == 2) { // If the temerature is between 10 and 99 degrees or -10 and -99... String t1 = t.substring(0, 1); // ...we need the first String t2 = t.substring(1, 2); // and second digit matrix.writeDigitRaw(0,0); matrix.writeDigitNum(1, t1.toInt()); // which we plot to second and third place of 7-seg matrix.writeDigitNum(3, t2.toInt()); if (c<0) {matrix.writeDigitRaw(0,64);} // and if the temperature is negative, we plot the minus sign to first place. } ; if (t.length() == 1) { // Other case is temperature between 0 and 9 or -1 to -9 String t1 = t.substring(0, 1); // Then we need only the first digit matrix.writeDigitRaw(0,0); matrix.writeDigitRaw(1,0); matrix.writeDigitNum(3, t1.toInt()); // And we plot it to third place of 7-seg if (c<0) {matrix.writeDigitRaw(1,64);} // and if the temerature is negative, we plot the minus sign to second place. }; matrix.writeDigitRaw(2, 0x10); // light up dot as degree sign matrix.writeDigitRaw(4,57); // and the letter C to fourth place matrix.writeDisplay(); delay(500); } delay(500); }