#include <stdio.h>
#include <math.h>
int main(void){
float pi=3.14159265;
float wave1p,wave2p,wave1h,wave2h;
float wavelength1,wavelength2,newp,timeinc;
float newheight;
//Read period and wave height for wave 1
printf("Input the period and wave height of wave 1\n");
scanf("%f %f\n",&wave1p,&wave1h);
//Read period and wave height for wave 2
printf("Input the period and wave height of wave 2\n");
scanf("%f %f\n",&wave2p,&wave2h);
//Compute and print wavelength for each wave
wavelength1=5.13*pow(wave1p,2);
wavelength2=5.13*pow(wave2p,2);
printf("Wave 1 Wavelength: %5.3f \n Wave 2 Wavelength: %5.3f \n",wavelength1,wavelength2);
//Set new period to product of wave periods
newp=wave1p*wave2p;
timeinc=newp/200;
float time=0, wavemax=0, steps=0, sum;
while(steps<=199)
{
newheight=(wave1h+wave2h)*sin(2*pi*time*(1/newp));
if (newheight>wavemax)
{
wavemax=newheight;
}
time=time+timeinc;
steps++;
}
printf("Wavemax: %3.4f\n",wavemax);
return 0;
}
#include <math.h>
int main(void){
float pi=3.14159265;
float wave1p,wave2p,wave1h,wave2h;
float wavelength1,wavelength2,newp,timeinc;
float newheight;
//Read period and wave height for wave 1
printf("Input the period and wave height of wave 1\n");
scanf("%f %f\n",&wave1p,&wave1h);
//Read period and wave height for wave 2
printf("Input the period and wave height of wave 2\n");
scanf("%f %f\n",&wave2p,&wave2h);
//Compute and print wavelength for each wave
wavelength1=5.13*pow(wave1p,2);
wavelength2=5.13*pow(wave2p,2);
printf("Wave 1 Wavelength: %5.3f \n Wave 2 Wavelength: %5.3f \n",wavelength1,wavelength2);
//Set new period to product of wave periods
newp=wave1p*wave2p;
timeinc=newp/200;
float time=0, wavemax=0, steps=0, sum;
while(steps<=199)
{
newheight=(wave1h+wave2h)*sin(2*pi*time*(1/newp));
if (newheight>wavemax)
{
wavemax=newheight;
}
time=time+timeinc;
steps++;
}
printf("Wavemax: %3.4f\n",wavemax);
return 0;
}
Homework
Hardware
int tempPin = 1;
int val;
int red=11;
int green=10;
int blue=9;
//int temp=0;
void setup() {
// put your setup code here, to run once:
pinMode(tempPin,INPUT);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val=analogRead(tempPin);
float mv=val*5000.0/1023;
float temp=(mv-500.0)/10;
Serial.println(val);
Serial.println("Temperature");
Serial.println(temp);
delay(500);
if(temp>22)
{
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
}
if(temp>=18 && temp<=22)
{
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
digitalWrite(blue,LOW);
}
if(temp<18)
{
digitalWrite(red,LOW);
digitalWrite(green,LOW);
digitalWrite(blue,HIGH);
}
}
Comments
Post a Comment