# temperature sensing code

Hi
I’ve written some code for a temperature sensing textile but it’s not working properly. It compiles as being correct, but when uploaded, the serial monitor and the led display do not correspond. Whatever the temperature I only get the last led display. Any advice greatly appreciated. Here’s the code:

``````float temp,tempAvg, tempA;

long previousMillis = 0;
long interval = 2000;

int count = 0;

int ledPin1 = 5;       //put the LED light on pin 5
int ledPin2 = 9;      //put the LED light on pin 9
int ledPin3 = 11;      //put the LED light on pin 11

/*int positivePin = A5;   //setting A5 to be a positive pin.*/

int brightness1 = 15;    // how bright the LED is
int fadeAmount1 = 5;    // how many points to fade the LED by

int brightness2 = 25;    // how bright the LED is
int fadeAmount2 = 5;    // how many points to fade the LED by

int brightness3 = 35;    // how bright the LED is
int fadeAmount3 = 10;    // how many points to fade the LED by

void setup() {

Serial.begin(57600);

pinMode(ledPin1, OUTPUT); //Setting LED 1 (lightPin1) to be an output. Ditto for each of the other LEDs
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);

};

void loop () {

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {

temp = temp - 0.5;
temp = temp / 0.01;

Serial.print("temp: ");
Serial.println(temp);

//tempAvg = tempAvg + temp;
//count++;
//if (count > 7) {
//  tempA = tempA - temp;
//  count = 0;
//}
//
//tempA = tempAvg/8.;
//
//  Serial.print("tempA: ");
//  Serial.println(tempA);

previousMillis = currentMillis;
}

if ((temp >= 18.0) && (temp < 23.0)) {

// set the brightness of all three LEDS:
analogWrite(ledPin1, max(brightness1, 0));
analogWrite(ledPin2, max(brightness2, 0));
analogWrite(ledPin3, max(brightness3, 0));

// change the brightness for next time through the loop:

} else if ((temp >= 23.0) && (temp < 28.0)) {
// do something else
void loop();

digitalWrite(ledPin1, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin1, LOW);    // sets the LED off
delay(1000);                  // waits for a second

digitalWrite(ledPin2, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin2, LOW);    // sets the LED off
delay(1000);                  // waits for a second

digitalWrite(ledPin3, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin3, LOW);    // sets the LED off
delay(1000);                  // waits for a second

}

else if ((temp >= 28.0) && (temp < 33.0)); {
// do something else
void loop();

digitalWrite(ledPin1, HIGH);   // sets the LED on
delay (200);                     //delay 20 miliseconds
digitalWrite(ledPin1, LOW);    //led off

digitalWrite(ledPin2, HIGH);
delay (200);
digitalWrite(ledPin2, LOW);

digitalWrite(ledPin3, HIGH);
delay (200);
digitalWrite(ledPin3, LOW);

}

delay(500);
``````
``````  // do something else
void loop();
``````

Why do you keep including a function prototype in your code?

The code you posted doesn't compile.

Should there be only one void loop? The code does compile when I use it but it's not doing what I want it to do. Maybe it copied incorrectly.