#include "Adafruit_LEDBackpack.h" #include "Adafruit_GFX.h" #include Adafruit_7segment matrix = Adafruit_7segment(); void setup() { Serial.begin(9600); // Start up the library for 7-seg and set max brightness // matrix.begin(0x70); // matrix.setBrightness(15); // wait for MAX chip to stabilize matrix.begin(0x70); matrix.setBrightness(15); delay(500); } void loop() { int sum = 0; for (int i=0; i <= 9; i++){ sum+=analogRead(0); delay(10); } int P=(sum/10/1024.0 + 0.095 )/0.0009; String t = String(P); Serial.println(P); if (t.length() == 4) { // If the pressure 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 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) { // If the pressure 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.writeDigitRaw(0,0); // (blank space on first digit) matrix.writeDigitNum(1, t1.toInt()); // which we plot to the first, second and third place of 7-seg matrix.writeDigitNum(3, t2.toInt()); matrix.writeDigitNum(4, t3.toInt()); } ; if (t.length() == 2) { // If the pressure is between 10 and 99 torr... String t1 = t.substring(0, 1); // ...we need the first String t2 = t.substring(1, 2); // and second digit matrix.writeDigitRaw(0,0); matrix.writeDigitRaw(1,0); matrix.writeDigitNum(3, t1.toInt()); // which we plot to second and third place of 7-seg matrix.writeDigitNum(4, t2.toInt()); } ; if (t.length() == 1) { // Other case is pressure between 0 and 9 String t1 = t.substring(0, 1); // Then we need only the first digit matrix.writeDigitRaw(0,0); matrix.writeDigitRaw(1,0); matrix.writeDigitRaw(3,0); matrix.writeDigitNum(4, t1.toInt()); // And we plot it to third place of 7-seg }; matrix.writeDisplay(); delay(400); }