Monday, February 2, 2009

here's a problem:
i got the thermisistor to work with one LED, but i was trying to attach a second, and I can't for the life of me get the second to have any brightness whatsoever. I've set it up in an if/else fashion, and wired the two LED's exactly the same way.
here's the way it's set up with a potentiometer instead of a thermisistor (the yellow LED is just hooked to the analog output of the potentiometer):







and here's the code:
int tempPin = 0; //analog input pin from temperature thing = 0
int tempValue = 0; //value read from the temp
int led = 9; //PWM pin that led is on - (PWM 0 = digpin 9)
int clearPin = 2; //pin the clear led is on
int redPin = 3; //pin the red led is on
int THRESHOLD = 860; //threshold of drinkability


void setup() {
pinMode(clearPin, OUTPUT); //clear led pin is an output pin
//initialize serial communication at 9600 bps:
Serial.begin(9600);
}


void loop() {
tempValue = analogRead(tempPin); //read the temperature value
analogWrite(led, tempValue/4); //PWM the led with temp value (divided by 4 to fit in a byte)
Serial.println(tempValue); //print the temp value back to the program
delay(10); //wait 10 ms before looping

if (tempValue <= THRESHOLD) {
digitalWrite(clearPin, HIGH); //turn on clear led
digitalWrite(redPin, LOW); //turn off red led

}

else {
digitalWrite(clearPin, LOW);
digitalWrite(redPin, HIGH);
}
}


any ideas?

No comments:

Post a Comment