串行监视器返回难以理解的字符arduino

时间:2014-07-22 18:34:46

标签: arduino

我添加了LED指示灯,打开我的草图,读取温度传感器值,现在我的串行监视器返回垃圾字符。我有一个初始化和控制LED的阵列。问题可能在于我的循环初始化和关闭LED?感谢。

const int temperaturePin = 0;

int leds[] = {13, 12, 11};

void setup(){
    Serial.begin(9600);
    for (int i = 0; i < 3; i--) {
        pinMode(leds[i], OUTPUT);
    }
}

void loop(){
  // Multiple declarations on one line
    float voltage, degreesC, degreesF;

  // Measure true voltage with custom function
    voltage = getVoltage(temperaturePin);

  // Convert voltage to degrees Celsius
  // This line compensates for an offset of .5
  // in the TMP36 temperature sensor
    degreesC = (voltage - 0.5) * 100.0;

  // Convert Celsius to Fahrenheit
    degreesF = degreesC * (9.0/5.0) + 32.0;
    Serial.print("Voltage: ");
    Serial.print(voltage);
    Serial.print(" Deg C: ");
    Serial.print(degreesC);
    Serial.print(" Deg F: ");
    Serial.println(degreesF);
    if ((degreesF >= 75) && (degreesF <= 76)) {
        digitalWrite(leds[0], HIGH);
    }
    else if ((degreesF >= 77) && (degreesF <= 78)) {
        digitalWrite(leds[1], HIGH);
    }
    else if ((degreesF >= 79) && (degreesF <= 80)) {
        digitalWrite(leds[2], HIGH);
    }

    for (int i = 0; i < 3; i++) {
        digitalWrite(leds[i], LOW);
    }

    delay(1000);
}

float getVoltage(int pin){
    return (analogRead(pin) * 0.004882814);
}

0 个答案:

没有答案