# Arduino Unoで12ピン7セグメントディスプレイとグローブ温度センサーをコーディングする際の問題

``````//Temperature Variables
//thermistor = value of the thermistor
int a;
float temperature;
int thermistor=3975;
float resistance;
boolean DigitOn = LOW;
boolean DigitOff = HIGH;
boolean SegOn=HIGH;
boolean SegOff=LOW;

int DigitPins[] = {2, 3, 4, 5};
int SegmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

//N is for numbers and NxP is a number with a decimal point behind
int BLANK[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int N0[]    = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW, LOW};
int N0P[]   = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW, HIGH};
int N1[]    = {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW};
int N1P[]   = {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW, HIGH};
int N2[]    = {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH, LOW};
int N2P[]   = {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH};
int N3[]    = {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH, LOW};
int N3P[]   = {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH, HIGH};
int N4[]    = {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW};
int N4P[]   = {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, HIGH};
int N5[]    = {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH, LOW};
int N5P[]   = {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH, HIGH};
int N6[]    = {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, LOW};
int N6P[]   = {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
int N7[]    = {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW};
int N7P[]   = {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW, HIGH};
int N8[]    = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW};
int N8P[]   = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
int N9[]    = {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH, LOW};
int N9P[]   = {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH, HIGH};
int MIN[]   = {LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW};

//Array of pointers for the 4 digits
int* lights[4];

//char array coming from the serial interface
//4 numbers or chars, 4 optional decimal points, 1 end-of-line char
char incoming[9] = {};

void setup() {
Serial.begin(19200);
for (byte digit=0;digit<4;digit++) {
pinMode(DigitPins[digit], OUTPUT);
}

for (byte seg=0;seg<8;seg++) {
pinMode(SegmentPins[seg], OUTPUT);
}

//initialize display with 1.234
lights[0] = N7;
lights[1] = N9P;
lights[2] = N3;
lights[3] = N4;
}

void loop() {
//Temperature Sensor
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/thermistor+1/298.15)-273.15;
//convert to temperature via datasheet ;
//delay(1000);
Serial.print("Current temperature is ");
Serial.println(temperature);
//delay(500);
//read the numbers and/or chars from the serial interface
if (Serial.available() > 0) {
int i = 0;
//clear the array of char
memset(incoming, 0, sizeof(incoming));
while (Serial.available() > 0 && i < sizeof(incoming) - 1) {
i++;
delay(3);
}
Serial.println(incoming);

//show the input values
for (int y = 0; y < 4; y++) {
Serial.print(y);
Serial.print(": ");
for (int z = 0; z < 8; z++) {
Serial.print(lights[y][z]);
}
Serial.println("");
}
}

//end if, i.e. reading from serial interface
//This part of the code is from the library SevSeg by Dean Reading

for (byte seg=0;seg<8;seg++) {
//Turn the relevant segment on
digitalWrite(SegmentPins[seg],SegOn);
//For each digit, turn relevant digits on
for (byte digit=0;digit<4;digit++){
if (lights[digit][seg]==1) {
digitalWrite(DigitPins[digit],DigitOn);
}
//delay(200); //Uncomment this to see it in slow motion
}
//Turn all digits off
for (byte digit=0;digit<4;digit++){
digitalWrite(DigitPins[digit],DigitOff);
}
//Turn the relevant segment off
digitalWrite(SegmentPins[seg],SegOff);
}
//end of for
}
``````
2
サイトが正しく解釈するように、コードの各行の先頭に4つのスペースを追加します。

@jmsテキストを手動でフォーマットしないでください。それには右のボタンを使います。 `{}`

SevSegライブラリのコードを使用していますが、スケッチにヘッダ `SevSeg.h` を含めていないようです。どのようにライブラリを使用していますか？

`7セグメント表示で温度を表示します。` - OK。正確に何が起こっていますか？