Day 5

For the lab i had to write a program that causes an LED to change color depending on the temperature


Here's the code
//Potentiometer Reading Program
const int POT=0; //Pot on analog pin 0
int val = 0; //variable to hold the analog reading from the POT
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

int ledMode = 0; //Cycle between LED states
void setup()
{
 Serial.begin(9600); //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 <= 139)
 {
digitalWrite(BLED,HIGH);
digitalWrite(GLED,LOW);
digitalWrite(RLED,LOW);

 }
if (val<=147 && val>=139)
{
  digitalWrite(GLED,HIGH);
  digitalWrite(BLED,LOW);
  digitalWrite(RLED,LOW);
}


if (val>147)
{
  digitalWrite(RLED,HIGH);
  digitalWrite(BLED,LOW);
  digitalWrite(GLED,LOW);
}


 Serial.println(val); //Print it to the serial port
 delay(500);
}

Heres a picture



















Here's a video of it working

Here is the wave homework 
Here is the first homework problem, generating 100 values for mi/h 














I could not modify the program to allow the user to specify the number of points to compute for determining the maximum combined wave height, or allow the user to specify the phase shift. However, i did get 3/5 modifications to work.

Comments

Popular posts from this blog

Day 22 Nov 14

Day 21 Nov 9