/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program determines wavelengths and wave height of open seawater */
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
/* Declare variables. */
double w1_ht, w2_ht, w1_L, w2_L, s1, s2, s1_user, s2_user, sum, time_incre, wavemax=0, time=0, steps, w1_period, w2_period, p_shift, trough, time_mwh, wavemax_spec, in_step;
/* Read the periods and wave heights of the two waves to be combined. */
printf("This program is designed to determine the wavelengths for two seperate waves. It will also compute the maximum height of the two waves when combined.\n");
printf("\nEnter a value for the period of your 1st wave. \n");
scanf("%lf", &w1_period);
printf("Enter the height for your 1st wave in meters. \n");
scanf("%lf", &w1_ht);
printf("Enter a value for the period of your 2nd wave. \n");
scanf("%lf", &w2_period);
printf("Enter the height of your 2nd wave in meters. \n");
scanf("%lf", &w2_ht);
printf("Enter how many times you want data to be computed to determine wavelengths and wave heights.\n");
scanf("%lf", &in_step);
printf("Enter a phase shift for the second wave from the first wave in degrees.\n");
scanf("%lf", &p_shift);
printf("If you want, enter a time in seconds after zero you'd want the max wave height for. \n");
scanf("%lf", &time_mwh);
/*(Compute and print the wavelengths of the individual waves*/
w1_L = 5.13 * w1_period * w1_period;
w2_L = 5.13 * w2_period * w2_period;
time_incre = (1/in_step)*w1_period * w2_period;
printf("\nThe wavelength of wave 1: %3.3lf m\n", w1_L * 0.3048);
printf("The wavelength of wave 2: %3.3lf m\n", w2_L * 0.3048);
s1_user = (w1_ht * 0.5) * sin (2 * PI * (1/w1_period) * time_mwh);
s2_user = (w2_ht * 0.5) * sin ((2 * PI * (1/w2_period) * time_mwh)+ (p_shift * PI / 180));
wavemax_spec = s1_user + s2_user;
/*Compute 200 values of the sum of the two waves and determine the maximum value*/
for (steps = 0; steps <= in_step; steps++)
{
time = (steps*time_incre);
s1 = (w1_ht * 0.5) * sin (2 * PI * (1/w1_period) * time );
s2 = (w2_ht * 0.5) * sin ((2 * PI * (1/w2_period) * time) + (p_shift * PI / 180));
sum = s1 + s2;
if (sum >= wavemax)
{
wavemax = sum;
}
if (sum <= trough)
{
trough = sum;
}
}
/*Print the maximum value*/
printf("Maximum combined wave height: %3.3lf m\n", wavemax*2);
printf("Maximum crest height:%3.3lf m\n", wavemax);
printf("Minimum trough depth:%3.3lf m\n", trough);
if (time_mwh > 0)
{
printf("Max combined wave height at %3.3lf sec: %3.3lf m", time_mwh, wavemax_spec*2);
}
else;
/* Exit program. */
return 0;
}
TEMPERATURE SENSOR
//Potentiometer Reading Program
const int POT=0; //Pot on analog pin 0
const int RLED=11; //Red LED on Pin 11
const int BLED=9; //Blue LED on Pin 9
const int GLED=10; //Green LED on Pin 10
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);
//HOT
if (val > 163)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
//Temperate
else if (val <163 && val > 146)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
//COLD
else if (val < 146)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
}
No comments:
Post a Comment