This should help some.
int temperaturePin = 0;
int LED[] = {
9, 10, 11}; //sets the pins
//9 = RED, 10=GREEN, 11= BLUE
const boolean ON = LOW; //defines ON as LOW
const boolean OFF = HIGH; //defines OFF as HIGH
//Predefined Colors
const boolean RED[] = {
ON, OFF, OFF};
const boolean GREEN[] = {
OFF, ON, OFF};
const boolean BLUE[] = {
OFF, OFF, ON};
const boolean YELLOW[] = {
ON, ON, OFF};
const boolean CYAN[] = {
OFF, ON, ON};
const boolean MAGENTA[] = {
ON, OFF, ON};
const boolean WHITE[] = {
ON, ON, ON};
const boolean BLACK[] = {
OFF, OFF, OFF};
void setup()
{
for(int i = 0; i < 3; i++){
pinMode(LED[i], OUTPUT); //Set the three LED pins as outputs
}
Serial.begin(115200); //Start the serial connection with the copmuter
//to view the result open the serial monitor
//last button beneath the file bar (looks like a box with an antenae)
}
/*
* getVoltage() - returns the voltage on the analog input defined by
* pin
*/
float getVoltage(int pin)
{
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
} //converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
void loop() {
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (temperature - .5) * 100; //converting from 10 mv per degree wit 500 mV offset
Serial.print(temperature);
Serial.println(" degrees centigrade");
delay(1000);
if(temperature < 430){
setColor(LED, BLUE);
}
else{
if(temperature >430 && temperature <440){
setColor(LED, GREEN);
}
else {
if(temperature >440 && temperature <450)
{
setColor(LED, GREEN);
}
else{
setColor(LED, BLACK);
}
}
}
}
void setColor(int* led, boolean* color){
for (int i = 0; i < 3; i++) {
digitalWrite(led[i], color[i]);
}
}
void setColor(int* led, const boolean* color){
boolean tempColor[] = { color[0], color[1], color[2] };
setColor(led, tempColor);
}