lab 5

Write the temperature alert sketch that the causes the LED to light blue when the temperature is cold (ice will be provided), red when the temperature is hot (from squeezing with your fingers) and green when the temperature is just right.

Code:
const int BLED = 9; //Blue LED on Pin 9
const int GLED = 10; //Green LED on Pin 10
const int RLED = 11; //Red LED on Pin 11
//Potentiometer Reading Program
const int POT = 0; //Pot on analog pin 0
int val = 0; //variable to hold the analog reading from the POT
void setup()
{
  Serial.begin(115200); //Start Serial Communication
  pinMode (BLED, OUTPUT); //Set Blue LED as Output
  pinMode (GLED, OUTPUT); //Set Green LED as Output
  pinMode (RLED, OUTPUT); //Set Red LED as Output
}
void loop()
{

  val = analogRead(POT); //Read one value from the POT

  if (val <= 125)
  {
    digitalWrite(RLED, LOW);
    digitalWrite(GLED, LOW);
    digitalWrite(BLED, HIGH);
  }
  else if (val >= 160)
  {
    digitalWrite(RLED, HIGH);
    digitalWrite(GLED, LOW);
    digitalWrite(BLED, LOW);
  }
  else if (val >= 175)
  {
    digitalWrite(RLED, HIGH);
    digitalWrite(GLED, LOW);
    digitalWrite(BLED, LOW);
    delay(100);
    digitalWrite(RLED, LOW);
    digitalWrite(GLED, LOW);
    digitalWrite(BLED, LOW);
    delay(50);
  }
  else
  {
    digitalWrite(RLED, LOW);
    digitalWrite(GLED, HIGH);
    digitalWrite(BLED, LOW);
  }
  Serial.println(val); //Print it to the serial port
  delay(1000);
}


Comments

Popular posts from this blog

Homework 6

Another Day 23

Homework4