Tuesday, September 11, 2018

day 5 lab

//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(9600); //Start Serial Communication
}
void loop()
{
 val = analogRead(POT); //Read one value from the POT
 Serial.println(val); //Print it to the serial port
 delay(500);
}

//Temperature Reading LED program
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
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(9600); //Start Serial Communication
}
void loop()
{
  double mV= val*5,  temp= abs(mV - 500)/10;
  val = analogRead(POT); //Read one value from the POT
  Serial.println("degrees C:" );
  Serial.println(temp); //Print it to the serial port
  delay(500);
 if (val<138)
 {
  digitalWrite(RLED, LOW);
  digitalWrite(GLED, LOW);
  digitalWrite(BLED, HIGH);
 }
   else if (val>148)
   {
   digitalWrite(RLED, HIGH);
   digitalWrite(GLED, LOW);
   digitalWrite(BLED, LOW);
   }
    else if(val=143)
    {
   digitalWrite(RLED, LOW);
   digitalWrite(GLED, HIGH);
   digitalWrite(BLED, LOW);
 }
 delay(1);
return;}

No comments:

Post a Comment