Day 12

/*  This program determines the maximum height of a wave that is the sum of two specified waves. */
#include <stdio.h>
#include <math.h>

#define PI 3.141593
#define FILENAME "balloon1.txt"
int main(void)
{
/*  Declare variables.  */

FILE *balloon;
/*  Open output file.  */
balloon = fopen(FILENAME,"w");
//fprintf(waves,"800\n");
double ts,te,period;
double alt(double t);
double v(double t);
double peek_a=0,peek_t;

printf("Enter start time and end time in hour (less then 48)\n");

scanf("%lf %lf",&ts,&te);
while(ts>=48||te>48||ts>te)
{
printf("Involid input\n");
printf("Enter start time and end time in hour (less then 48)\n");
scanf("%lf %lf",&ts,&te);
}

printf("Enter the period in minite\n");
scanf("%lf",&period);
while(period<0)
{
printf("Involid input\n");
printf("Enter the period in minite\n");
scanf("%lf",&period);
}


period/=60;

fprintf(balloon,"Time(h) Altitude(m) Velocity(m/s)\n");


double c=floor((te-ts)/period);

for(int i=0;i<=c;i++)
{
double t=ts+i*period;
fprintf(balloon,"%7.4f %8.2f %8.2f\n",t,alt(t),v(t));
if(alt(t)>peek_a)
{
peek_a=alt(t);
peek_t=t;
}
}
printf("\nPeek Altitude is %8.2f at %.2f(h) \n",peek_a,peek_t);

fprintf(balloon,"\nPeek Altitude is %8.2f at %.2f(h) \n",peek_a,peek_t);




fclose(balloon);/*   Close file and exit program.   */
return 0;
}











double alt(double t)
{
return -.12*t*t*t*t+12*t*t*t-380*t*t+4100*t+220;
}

double v(double t)
{
return (-.48*t*t*t+36*t*t-760*t+4100)/3600;
}



Time(h) Altitude(m) Velocity(m/s)
      1  3951.88     0.94
 1.0833  4230.79     0.92
 1.1667  4504.94     0.91
 1.2500  4774.39     0.89
 1.3333  5039.18     0.87
 1.4167  5299.33     0.86
 1.5000  5554.89     0.84
 1.5833  5805.91     0.83
 1.6667  6052.41     0.81
 1.7500  6294.44     0.80
 1.8333  6532.03     0.78
 1.9167  6765.23     0.77
      2  6994.08     0.76
 2.0833  7218.61     0.74
 2.1667  7438.86     0.73
 2.2500  7654.86     0.71
 2.3333  7866.67     0.70
 2.4167  8074.30     0.69
 2.5000  8277.81     0.67
 2.5833  8477.23     0.66
 2.6667  8672.60     0.64
 2.7500  8863.95     0.63
 2.8333  9051.32     0.62
 2.9167  9234.75     0.60
      3  9414.28     0.59
 3.0833  9589.94     0.58
 3.1667  9761.77     0.57
 3.2500  9929.80     0.55
 3.3333 10094.07     0.54
 3.4167 10254.63     0.53
 3.5000 10411.49     0.52
 3.5833 10564.71     0.50
 3.6667 10714.31     0.49
 3.7500 10860.33     0.48
 3.8333 11002.81     0.47
 3.9167 11141.78     0.46
      4 11277.28     0.45
 4.0833 11409.34     0.43
 4.1667 11538.00     0.42
 4.2500 11663.29     0.41
 4.3333 11785.24     0.40
 4.4167 11903.90     0.39
 4.5000 12019.29     0.38
 4.5833 12131.45     0.37
 4.6667 12240.42     0.36
 4.7500 12346.22     0.35
 4.8333 12448.90     0.34
 4.9167 12548.48     0.33
      5    12645     0.32
 5.0833 12738.49     0.31
 5.1667 12828.99     0.30
 5.2500 12916.52     0.29
 5.3333 13001.13     0.28
 5.4167 13082.84     0.27
 5.5000 13161.69     0.26
 5.5833 13237.71     0.25
 5.6667 13310.93     0.24
 5.7500 13381.39     0.23
 5.8333 13449.11     0.22
 5.9167 13514.13     0.21
      6 13576.48     0.20
 6.0833 13636.19     0.19
 6.1667 13693.30     0.19
 6.2500 13747.83     0.18
 6.3333 13799.82     0.17
 6.4167 13849.30     0.16
 6.5000 13896.29     0.15
 6.5833 13940.84     0.14
 6.6667 13982.96     0.14
 6.7500 14022.70     0.13
 6.8333 14060.08     0.12
 6.9167 14095.13     0.11
      7 14127.88     0.11
 7.0833 14158.36     0.10
 7.1667 14186.61     0.09
 7.2500 14212.65     0.08
 7.3333 14236.51     0.08
 7.4167 14258.22     0.07
 7.5000 14277.81     0.06
 7.5833 14295.31     0.05
 7.6667 14310.75     0.05
 7.7500 14324.16     0.04
 7.8333 14335.57     0.03
 7.9167 14345.00     0.03
      8 14352.48     0.02
Peek Altitude is 14352.48 at 8(h)


lab
//LCD with Progress Bar
//Include the library code:
#include <LiquidCrystal.h>
//Reads Temp from I2C temperature sensor and prints it on the serial port
//Include Wire I2C library
#include <Wire.h>
int temp_address = 73; //1001000 written as decimal number
int speakerPin = 12 ;
//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//Create the progress bar characters

int count = 0;
byte deg[8] = {
  B00100,
  B01010,
  B00100,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};
void setup()
{
  Wire.begin();
  //Set up the LCDs number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Temperature");
  //Make progress characters
  //lcd.createChar(0, deg);
 // Serial.println(button);
  Serial.begin(9600);
  //Make progress characters
  lcd.createChar(0, deg);


}

void loop()
{
//Send a request
 //Start talking to the device at the specified address
 Wire.beginTransmission(temp_address);
 //Send a bit asking for register zero, the data register
 Wire.write(0);
 //Complete Transmission
 Wire.endTransmission();
 //Read the temperature from the device
 //Request 1 Byte from the specified address
 Wire.requestFrom(temp_address, 1);
 //Wait for response
 while(Wire.available() == 0);
 //Get the temp and read it into a variable
 int c = Wire.read();
 //Do some math to convert the Celsius to Fahrenheit
 int f = round(c*9.0/5.0 +32.0);
 //Send the temperature in degrees C and F to the serial monitor

  
  
  
 
 int button = analogRead(A0);
  lcd.setCursor(0, 1);
  if (button == 742)
    count++;
  if (count >= 2)
    count = 0;
  if (count == 0)
  {
    lcd.print(c);
    lcd.write((byte)0);
    lcd.print("C ");
  }
  if (count == 1)
  {
    
    lcd.print(f);
    lcd.write((byte)0);
    lcd.print("F ");
  }

if(c>=27)
{
tone(speakerPin, 3000,1000);
delay(1000);
}
// print out the value you read:

delay(500);
}

Comments

Popular posts from this blog

Homework3

Homework 5

Day10