Thursday, December 13, 2018

elevation

/* This program determines the locations of peaks in an */
/* grid of elevation data. */
#include <stdio.h>
#include <math.h>
#define N 25
#define FILENAME "grid1.txt"
int main(void)
{
/* Declare variables. */
int nrows, ncols, i, j;
double elevation[N][N], Pcount = 0, Vcount = 0, valley, peak = 0, temp_peak, Peak1Dis;
FILE *grid;
/* Read information from a data file. */
grid = fopen("grid1.txt","r");
if (grid == NULL)
printf("Error opening input file\n");

else
{
fscanf(grid,"%d %d",&nrows,&ncols);

for (i=0; i<=nrows-1; i++)
for (j=0; j<=ncols-1; j++)
fscanf(grid,"%lf",&elevation[i][j]);

/* Determine and print peak locations. */

printf("Top left point defined as row 0, column 0 \n");
printf("Bottom left point(BLF) defined as row 5, column 0 \n\n");
for (i=1; i<=nrows-2; i++)
for (j=1; j<=ncols-2; j++)
if ((elevation[i-1][j]<elevation[i][j]) && (elevation[i+1][j]<elevation[i][j]) && (elevation[i][j-1]<elevation[i][j]) && (elevation[i][j+1]<elevation[i][j]))
{
++Pcount;
printf("Peak at row: %d column: %d \n",i,j);
Peak1Dis = 100* sqrt(((5-i)*(5-i))+(j*j));
printf("Distance from BLP: %.2lf ft\n\n", Peak1Dis);
if (elevation[i][j] > peak)
{
peak = elevation[i][j];
}
}
printf("\nNumber of peaks: %lf\n\n", Pcount);

/* Determine and print valley locations. */
valley = elevation[i][j]; //initializes a variable to check lowest elevation against
for (i=1; i<=nrows-2; i++)
for (j=1; j<=ncols-2; j++)
if ((elevation[i-1][j]>elevation[i][j]) && (elevation[i+1][j]>elevation[i][j]) && (elevation[i][j-1]>elevation[i][j]) && (elevation[i][j+1]>elevation[i][j])
&& (elevation[i-1][j-1]>elevation[i][j]) && (elevation[i-1][j+1]>elevation[i][j]) && (elevation[i+1][j-1]>elevation[i][j]) && (elevation[i+1][j+1]>elevation[i][j]))
{
++Vcount;
printf("Valley at row: %d column: %d \n",i,j);
if (elevation[i][j] < valley)
{
valley = elevation[i][j];
}
}

printf("\nNumber of valleys: %lf\n", Vcount);
printf("\nHighest elevation: %lf\n", peak);
printf("Lowest elevation: %lf\n", valley);

fclose(grid); /* Close file. */
}
return 0; /* Exit program. */
}

sesimic

/* This program reads a seismic data file and then */
/* determines the times of possible seismic events. */

#include <stdio.h>
#define FILENAME "seismic1.txt"
#define MAX_SIZE 1000

int main(void)
{

/* Declare variables and function prototypes. */
int k, npts, short_window, long_window, counter = 0;
double sensor[MAX_SIZE], time_incr, short_power, threshold = 0,
long_power, ratio;
FILE *file_ptr;
double power_w(double *ptr,int n);

/* Read sensor data file. */
file_ptr = fopen(FILENAME,"r");
if (file_ptr == NULL)
printf("Error opening input file. \n");
else
{
fscanf(file_ptr,"%d %lf",&npts,&time_incr);
if (npts > MAX_SIZE)
printf("Data file too large for array. \n");
else
{

/* Read data into an array. */
for (k=0; k<=npts-1; k++)
fscanf(file_ptr,"%lf",&sensor[k]);

/* Read window sizes from the keyboard. */
printf("Enter number of points for short window: \n");
scanf("%d",&short_window);
printf("Enter number of points for long window: \n");
scanf("%d",&long_window);
while(threshold <= 1)
{
printf("Enter threshold value: \n");
scanf("%lf",&threshold);
}

/* Compute power ratios and search for events. */
for (k=long_window-1; k<=npts-1; k++)
{
short_power = power_w(&sensor[k],short_window);
long_power = power_w(&sensor[k],long_window);
ratio = short_power/long_power;
if (ratio > threshold)
{
printf("Possible event at %f seconds \n", time_incr*k);
counter++;
}
}
printf("Number of events: %d \n", counter);
/* Close file. */
fclose(file_ptr);
}
}
return 0;
}

/*????????????????????????????????????????????????????????????-*/
/* This function computes the average power in a specified */
/* window of a double array. */
double power_w(double *ptr, int n)
{

/* Declare and initialize variables. */
int k;
double xsquare=0;

/* Compute sum of values squared in the array x. */
for (k=0; k<=n-1; k++)
xsquare += *(ptr-k)*(*(ptr-k));

/* Return the average squared value. */
return xsquare/n;
}

Weather Ballon

#include <stdio.h>
#include <math.h>
#define FILENAME "balloon1.txt"
int main(void)
{
/*  Declare variables.  */
double start_time_hour, start_time_minute, end_time_hour, end_time_minute, time_passed_hour, time_passed_minute;
double incre_min, total_time, time_incre, alt, vel, max_alt, max_time_of_alt;
double Ptime, Palt, Pvel, datapoints;
FILE *balloon;

/*  Open output file.  */
balloon = fopen(FILENAME,"w");

/*  Get user input from the keyboard.  */
do
{
printf("Enter start time of weather balloon release in hrs then min. \n");
printf("start time: \n");
scanf("%lf %lf", &start_time_hour, &start_time_minute);
printf("\nEnter final time of weather balloon traveling in hrs then min. \n");
printf("final time: \n");
scanf("%lf %lf",&end_time_hour, &end_time_minute);

/*  Determine length of time passed based on user inputted times  */
time_passed_hour = end_time_hour - start_time_hour;
time_passed_minute = end_time_minute - start_time_minute;
total_time = time_passed_hour + (time_passed_minute / 60);
/* Checks data entered to see if valid */
if (end_time_hour < start_time_hour)
{
printf("\nStart time is greater than final time. Please reenter time values again.\n\n");
}
    if (end_time_hour > 48)
{
printf("\nFinal time value cannot be greater than 48 hours. Please reenter time values again.\n\n");
}
} while (end_time_hour < start_time_hour || (end_time_hour > 48));

printf("\nEnter time increment in minutes.\n");
printf("time increment: \n");
scanf("%lf",&incre_min);

double unceil_step = (total_time * 60) / incre_min;
double steps = ceil((total_time * 60) / incre_min);

/*  Determine altitudes and velocites of balloon  */
//fprintf(balloon,"(time(hrs)) (alitude(m)) (velocity(m/s))\n");
fprintf(balloon,"%lf\n", steps + 1 );
for (double k = 0; k <= steps; k++)
{
double T = (k*(total_time/unceil_step)) + start_time_hour;
alt = -0.12*pow(T,4) + 12*pow(T,3) - 380*pow(T,2) + 4100*T + 220;
vel = -0.48*pow(T,3) + 36*pow(T,2) - 760*T + 4100;
if(alt > max_alt)
{
max_alt = alt;
max_time_of_alt = T;
};
fprintf(balloon,"%.6lf %.6lf %.6lf\n", T, alt, vel/3600);
}
fprintf(balloon, "\nmax alitude: %.3lf m\n", max_alt);
fprintf(balloon, "\ntime of max alitude: %.3lf hrs\n", max_time_of_alt);
fclose(balloon);
/*   Close file and exit .   */

balloon = fopen("balloon1.txt","r");
fscanf(balloon," %lf", &datapoints);
printf("\nTIME ALT VEL\n");
for (double w = 1; w <= datapoints; w++ )
{
fscanf(balloon,"%lf %lf %lf",&Ptime,&Palt,&Pvel);
printf("%1.6lf %.6lf %.6lf\n",Ptime,Palt,Pvel);
}
printf("\nmax alitude: %.3lf m\n", max_alt);
printf("\ntime of max alitude: %.3lf hrs\n", max_time_of_alt);

return 0;
}

DNA strings

/*??????????????????????????????????????????????????????????????-*/
/* This program initializes a long character string and a short */
/* character string. It then prints the locations of the short */
/* string in the long string. It also prints the number of */
/* occurrences of the short string in the long string. */
#include <stdio.h>
#include <string.h>
#define long_leng 26
#define short_leng 3

int main(void)
{
/* Declare and initialize variables. */
int count=0;

printf("Enter sequence for long string DNA: ");
char long_str[long_leng];
scanf("%s", long_str);

printf("Enter sequence for short string DNA: ");
char short_str[short_leng];
scanf("%s", short_str);

char *ptr1=long_str, *ptr2=short_str;
/* Count the number of occurrences of short_str in long_str. */
/* While the function strstr does not return NULL, increment */
/* count and move ptr1 to next character of the long string. */
while ((ptr1=strstr(ptr1,ptr2)) != NULL)
{
printf("location %i \n",ptr1-long_str+1);
count++;
ptr1++;
}
/* Print number of occurrences. */
printf("number of occurrences: %i \n",count);
printf("\nLong String of DNA: ");
printf(long_str);
printf("\nShort String of DNA: ");
printf(short_str);
/* Exit program. */
return 0;
}

structures_waves2

#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr;
char location[20];
double fatalities, max_height;

};
int main(void)
{
/* Declare variables. */
int k=0, npts;
double max=0, sum=0, ave;
struct tsunami t[100];
{
FILE *waves2;
/* Read and print information from the file. */
waves2 = fopen(FILENAME,"r");
if (waves2 == NULL)
printf("Error opening data file. /n");
else
{
while (fscanf(waves2,"%d %d %d %s %lf %lf ",&t[k].mo,&t[k].da,
&t[k].yr, t[k].location, &t[k].fatalities,&t[k].max_height,) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
max = t[k].max_height;
k++;
}
npts = k;
//ave = sum/npts;
printf("Summary Information for Tsunamis /n");
printf("Maximum Wave Height (in feet): %.2f /n",max*3.28);
printf("Average Wave Height (in feet): %.2f /n",ave*3.28);
printf("Tsunamis with greater than average heights: /n");
for (k=0; k <=npts-1; k++)
printf("%s /n",t[k].location);
fclose(waves2);
}
return 0;
}
}

handprint

#include <iostream>
#include <cmath>
using namespace std;
#define FILENAME "handprint.txt"

int main(void)
{
const int N=20;
int k=0, npts=N;
double y[N];
//Declare and initialize variables.
//double unknown[5]={5.4,7.2,7.9,7.4,5.1},
double known[5]={6.2,7.0,8.0,7.4,5.8},
//test[5]={};
double distance(double hand_1[5],double hand_2[5]);
ifstream handprint;
// Open file, read data into an array.
handprint.open(FILENAME);
if (handprint.fail())
cout << "Error opening input file." << endl;
else
{
while (!handprint.eof())
{
handprint >> y[k];
k++;
}
npts = k;
// Find and print the maximum value.

// Compute and print distance.
cout << "Enter distances for each digit starting with the thumb:" << endl;
/*for (int i = 0; i < 5; i++)
{cin >> test[i];}*/

cout << "Distance: " << distance(y,known) << endl;
// Exit program.
return 0;
}

//-----------------------------------------------------------------
//  This function computes the distance between two hand measurements.
double distance(double hand_1[5],double hand_2[5])
{
//  Declare variables.
int k;
double sum=0;
//  Compute sum of absolute value differences.
for (k=0; k<=4; k++)
sum = sum + fabs(hand_1[k]-hand_2[k]);
//  Return distance value.
return sum;
}

classes "date"

#include <iostream>

#include <cmath>

using namespace std;

class date

{

// prototypes for public members.

public:

void input();

void print_slash();

void print_comma();


// Declare private data members.

private:

int day, month, year;

};


void date::input()

{

cin >> day >> month >> year;

}

// This function prints the date as month/day/year.

void date::print_slash()

{

cout << month << "/" << day << "/" << year << "\n";

}

// This function prints the date as month day, year.

void date::print_comma()

{

switch(month)
{
case 1:
{cout << "Jan" << " " << day << "," << year << "\n";
break;
}
case 2:
{cout << "Feb" << " " << day << ","<< year << "\n";
break;
}
case 3:
{cout << "Mar" << " "  << day << ","<< year << "\n";
break;
}
case 4:
{cout << "Apr" << " "  << day << ","<< year << "\n";
break;}
case 5:
{cout << "May" << " "  << day << ","<< year << "\n";
break;}
case 6:
{cout << "Jun" << " "  << day << ","<< year << "\n";
break;
}
case 7:
{cout << "Jul" << " "  << day << ","<< year << "\n";
break;}
case 8:
{cout << "Aug" << " "  << day << ","<< year << "\n";
break;
}
case 9:
{cout << "Sep" << " "  << day << ","<< year << "\n";
break;
}
case 10:
{cout << "Oct" << " " << day << ","<< year << "\n";
break;
}

case 11:
{cout << "Nov" << " " << day << ","<< year << "\n";
break;
}
case 12:
{cout << "Dec" << " " << day << ","<< year << "\n";
break;
}
}
}
_________________________________________________________________________________

#include <iostream>

#include <cmath>

#include "date.h"

using namespace std;

// Declare and initialize variables.

int main(void)

{

date date;
// Read input date.
cout << "Please enter the date as day, month, year" << endl;
date.input();

// Print date in comma and slash form.

cout << "Date in slash form:" << endl;

date.print_slash();

cout << "Date in comma form:" << endl;

date.print_comma();

// Exit program.

return 0;

}

Project 3

#include <SD.h>
#include <Wire.h>
#include "BMP180Lib.h"
#include <SoftwareSerial.h>
BMP180lib bmp180; //create an instance of the BMP180 library to able to use functions in BMP180lib.h.
SoftwareSerial ss (9, 8);
//Set by default for the SD card library
//MOSI = pin 11
//MISO = pin 12
//SCLK = pin 13
const int CS_PIN = 10;
// make it long enough to hold your longest file name, plus a null terminator
char filename[16];
//manually input desired filename here before each test
char *s = "LOG_";
const int alarm = 3;
const float p0 = 101325; // Pressure at sea level (Pa)
float altitude, apogee = 0;
unsigned int ut = 0;
unsigned long up = 0, previousTime = 0;
long timeStamp = 0, temperature = 0, pressure = 0;
double accel = 0;
int START = 0, x1 = 0, y1 = 0, z1 = 0, interval = 750;
float x_g = 0, y_g = 0, z_g = 0;
const unsigned char UBX_HEADER[] = { 0xB5, 0x62 };    //the first two bits for every UBX message from NEO-6M

struct NAV_POSLLH { //structure to read in values from the NAV_POSLLH UBX message coming from the NEO-6M GPS
  unsigned char cls;
  unsigned char id;
  unsigned short len;
  unsigned long iTOW;
  long lon;
  long lat;
  long height;
  long hMSL;
  unsigned long hAcc;
  unsigned long vAcc;
};

NAV_POSLLH posllh;

void setup()
{
  pinMode(CS_PIN, OUTPUT);
  pinMode(alarm, OUTPUT);
  Serial.begin(57600);
  ss.begin(9600); //initialize software serial port at 9600 baud
  Wire.begin();   //Create a Wire object
  bmp180.Calibration(); //BMP180 function needed to be ran each time to make sure sensor is accurate

  Serial.println("Initializing Card");
  //CS pin is an output

  if (SD.begin(CS_PIN))
  {
    Serial.println("Card Ready");
  }
  else
  {
    Serial.println("Card Failed");
    return;
  }
  int n = 0;
  snprintf(filename, sizeof(filename), "%s%02d.csv", s, n); // includes a two-digit sequence number in the file name
  while (SD.exists(filename)) {
    n++;
    snprintf(filename, sizeof(filename), "%s%02d.csv", s, n);
  }
  File dataFile = SD.open(filename, FILE_READ);
  Serial.println(n);
  Serial.println(filename);
  dataFile.close();
  //now filename[] contains the name of a file that doesn't exist
  if ( processGPS() )
  {
    //      Serial.print("
  }
}

void loop()
{
  timeStamp = millis();
  unsigned long currentTime = millis();

  read_ADXL();
  read_BMP180();  // function for getting data values from BMP180 sensor. Also detects apogee.

  if (START == 1) //once "z_g" is detected above 3,
  {
    Serial.println(altitude, 2);
    Serial.print(x_g);
    Serial.print(", ");
    Serial.print(y_g);
    Serial.print(", ");
    Serial.println(z_g);
    if ( processGPS() )
    {
      Serial.print(posllh.lat / 10000000.0f, 4);
      Serial.print(",");
      Serial.println(posllh.lon / 10000000.0f, 4);
    }
    Serial.println();
  }
  else
  {
    if (currentTime - previousTime >= interval)
    {
      previousTime = currentTime;
      Serial.println("Awaiting launch");
      tone(alarm, 466, 200);
      delay(50);
    }
  }

  if (altitude <= 250 && apogee > 500)
  {
    Serial.print("Apogee: ");
    Serial.println(apogee);
  }

  File dataFile = SD.open(filename, FILE_WRITE);
  if (dataFile)
  {
    dataFile.print(timeStamp);
    dataFile.print(",");
    dataFile.print(pressure, DEC);
    dataFile.print(",");
    dataFile.print(altitude, 2);
    dataFile.print(",");
    dataFile.print(x_g);
    dataFile.print(",");
    dataFile.print(y_g);
    dataFile.print(",");
    dataFile.print(z_g);
    dataFile.print(",");
    if ( processGPS() )
    {
      dataFile.print(posllh.lat / 10000000.0f, 4);
      dataFile.print(",");
      dataFile.print(posllh.lon / 10000000.0f, 4);
    }
    dataFile.println();
    dataFile.close(); //Data isn't actually written until we close the connection!
  }
  else
  {
    Serial.println("Couldn't open log file");
  }
  tone(alarm, 262, 5);
}

void read_ADXL()
{ //the reading, converting and storing of acceleration values happen here. Also, when "START" is set to 1, data streaming and writing commences.
  x1 = analogRead(A1);
  y1 = analogRead(A2);
  z1 = analogRead(A3);
  x_g = ( ( ( (double)(x1 * 5) / 1024) - 1.65 ) / 0.330 );
  y_g = ( ( ( (double)(y1 * 5) / 1024) - 1.65 ) / 0.330 );
  z_g = ( ( ( (double)(z1 * 5) / 1024) - 1.65 ) / 0.330 );
  if (z_g > 3)
  {
    START = 1;
  }
}

void read_BMP180()
{ //this groups all the fucntions related to the BMP180 sensor, stores the value of the altitude and apogee.
  ut = bmp180.ReadUT();
  up = bmp180.ReadUP();
  temperature = bmp180.GetTemperature(ut);
  pressure = bmp180.GetPressure(up);
  altitude = (float)44330 * (1 - pow(((float) pressure / p0), 0.190295));
  if (altitude >= apogee)
  {
    apogee = altitude;
  }
}

void calcChecksum(unsigned char* CK) {//this function was written by Youtube Content Creator iforce2d. This is what performs the checksum on an individual bit in the UBX GPS message.
  memset(CK, 0, 2);
  for (int i = 0; i < (int)sizeof(NAV_POSLLH); i++) {
    CK[0] += ((unsigned char*)(&posllh))[i];
    CK[1] += CK[0];
  }
}

bool processGPS() {//this function was written by Youtube Content Creator iforce2d. It reads the 34-bit binary NAV_POSLLH UBX message coming from the NEO-6M GPS and verifies each bit against the checksum for the message.
  static int fpos = 0;
  static unsigned char checksum[2];
  const int payloadSize = sizeof(NAV_POSLLH);

  while ( ss.available() ) {
    byte c = ss.read();
    if ( fpos < 2 ) {
      if ( c == UBX_HEADER[fpos] )
        fpos++;
      else
        fpos = 0;
    }
    else {
      if ( (fpos - 2) < payloadSize )
        ((unsigned char*)(&posllh))[fpos - 2] = c;

      fpos++;

      if ( fpos == (payloadSize + 2) ) {
        calcChecksum(checksum);
      }
      else if ( fpos == (payloadSize + 3) ) {
        if ( c != checksum[0] )
          fpos = 0;
      }
      else if ( fpos == (payloadSize + 4) ) {
        fpos = 0;
        if ( c == checksum[1] ) {
          return true;
        }
      }
      else if ( fpos > (payloadSize + 4) ) {
        fpos = 0;
      }
    }
  }
  return false;
}

project 2

#include <LiquidCrystal.h>
#include "VernierLib.h" //library available from Veriner into interface with their sensors
VernierLib Vernier; //create an instance of the VernierLib library to able to use functions in Vernierlib.h
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

const int selectButton = 4;
const int leftButton = 5;
const int rightButton = 6;
const int CCWpin = 2; //pin for counterclockwise direction
const int CWpin = 3; //pin for clockwise direction
int Bpress = 1; //counter to keep track of button presses
float sensorReading; //use to store analog sensor reading
double displacement = 0; //variable for displacement wheel conversion to millimeters

volatile int counter = 0; //varible for displacement wheel counting

void setup() {
  Serial.begin(9600); //start serial communication
  Vernier.autoID(); //identify the analog sensor being used. Only one sensor can be detected with Autoint with additional multiplexers to interface multiple with one arduino.
  pinMode(CCWpin, INPUT_PULLUP); //setup CCW pin
  pinMode(CWpin, INPUT_PULLUP); //setup CW pin
  pinMode(selectButton, INPUT);
  pinMode(leftButton, INPUT);
  pinMode(rightButton, INPUT);
  lcd.begin(16,2);        // '16,2' is 16 columns, 2 rows on the display
  digitalWrite(CCWpin, LOW); //initialize CCW pin status
  digitalWrite(CWpin, HIGH); //initialize CW pin status
  attachInterrupt(digitalPinToInterrupt(CCWpin), movingCCW, RISING); //trigger when pin goes from LOW to HIGH
  attachInterrupt(digitalPinToInterrupt(CWpin), movingCW, FALLING); //trigger when pin goes from HIGH to LOW
  Serial.println("Dist  Force  Time");
  Serial.print("\n");
 }

void loop() {
  displacement = counter*0.1; //converts angular movement of displacement wheel to linear displacement of tackle
  sensorReading = Vernier.readSensor(); //readSensor reads the voltage from BTA sensor and automatically converts to units of newtons
  lcd.setCursor(0,0);
  lcd.print(millis() / 1000.0, 3); //time since arduino turned/reset
  lcd.print(" sec       ");
 
  if (digitalRead(leftButton) == HIGH)
    { //this increments through the 3 screens to the left
      Bpress++;
        if (Bpress > 3) //ensures the user doesnt go past the thrid screen
          {
            Bpress = 3;
          }
    }
 
  if (digitalRead(rightButton) == HIGH)
    { //this increments through the 3 screens to the right
      Bpress--;
        if (Bpress < 0) //ensures user doesnt go past the first screen
          {
            Bpress = 1;
          }
    }
   
  switch(Bpress)  //each case shows different screen on LCD
    {
      case 1: //this is default when arduino is powered on
        DispToLCD();
        break;
      case 2: // 2nd screen
        ForceToLCD();
        break;
      case 3: //3rd screen
        serialConnection();
        break;
    }
  delay(250); //wait quarter second
}

void ForceToLCD()
{ //function shows force sensor data when called on LCD
  lcd.setCursor(0,0);
  lcd.print(millis() / 1000.0, 3); //this expression makes time show with decimals for better accuracy
  lcd.print(" sec");
  lcd.setCursor(0,1);
  lcd.print("Force: ");
  lcd.print(sensorReading); //print force data value
  lcd.print(Vernier.sensorUnits()); //vernier lib function that auto detects correct units for sensor used
  lcd.print(" ");
}

void DispToLCD()
{ //function shows displacement data when called on LCD
  lcd.setCursor(0,0);
  lcd.print(millis() / 1000.0, 3); //this expression makes time show with decimals for better accuracy
  lcd.print(" sec");
  lcd.setCursor(0,1);
  lcd.print("Disp: ");
  lcd.print(displacement);  //resolution of displacement sensor is 0.1mm.
  lcd.print(" mm   ");
}

void DataToSerial()
{ //function to print all sensor data to serial when called
  Serial.print(displacement); //resolution of displacement sensor is 0.1mm.
  Serial.print("  "); //space to make data look nice on serial monitor
  Serial.print(sensorReading); //print force data value
  Serial.print("   "); //print a space
  Serial.println(millis() / 1000.0, 3); //this expression makes time show with decimals for better accuracy
  Serial.print("\n");
}

void serialConnection()
{ //function asks user if they want to send data over serial and awaits for select button to be held to initiate
  lcd.setCursor(0,0);
    lcd.print("send data to pc");
    lcd.setCursor(0,1);
    lcd.print("over serial?   ");
    if (digitalRead(selectButton) == HIGH)  //when the select button is held down data will be sent to PC over serial bus
    {
      DataToSerial();
      lcd.setCursor(0,0);
      lcd.print("serial monitor  ");
      lcd.setCursor(0,1);
      lcd.print("running on pc   ");
    }
}

void movingCCW()
{ //counts with interrupt as displacement wheel is turned counterclockwise
    counter++; //count UP
}

void movingCW()
{ //counts with interrupt as displacement wheel is turned clockwise
    counter--; //count DOWN
}   

Thursday, October 4, 2018

Day 11 Homework

#include <stdio.h>
#include <math.h>
#define FILENAME "balloon1.txt"
int main(void)
{
/* Declare variables. */
double start_time_hour, start_time_minute, end_time_hour, end_time_minute, time_passed_hour, time_passed_minute;
double incre_min, total_time, time_incre, alt, vel, max_alt, max_time_of_alt;
FILE *balloon;

/* Open output file. */
balloon = fopen(FILENAME,"w");

/* Get user input from the keyboard. */
do
{
printf("Enter start time of weather balloon release in hrs then min. \n");
printf("start time: \n");
scanf("%lf %lf", &start_time_hour, &start_time_minute);
printf("\nEnter final time of weather balloon traveling in hrs then min. \n");
printf("final time: \n");
scanf("%lf %lf",&end_time_hour, &end_time_minute);

/* Determine length of time passed based on user inputted times */
time_passed_hour = end_time_hour - start_time_hour;
time_passed_minute = end_time_minute - start_time_minute;
total_time = time_passed_hour + (time_passed_minute / 60);
/* Checks data entered to see if valid */
if (end_time_hour < start_time_hour)
{
printf("\nStart time is greater than final time. Please reenter time values again.\n\n");
}
if (end_time_hour > 48)
{
printf("\nFinal time value cannot be greater than 48 hours. Please reenter time values again.\n\n");
}
} while (end_time_hour < start_time_hour || (end_time_hour > 48));

printf("\nEnter time increment in minutes.\n");
printf("time increment: \n");
scanf("%lf",&incre_min);

double unceil_step = (total_time * 60) / incre_min;
double steps = ceil((total_time * 60) / incre_min);

/* Determine altitudes and velocites of balloon */
fprintf(balloon,"(time(hrs)) (alitude(m)) (velocity(m/s))\n");
for (double k = 0; k <= steps; k++)
{
double T = (k*(total_time/unceil_step)) + start_time_hour;
alt = -0.12*pow(T,4) + 12*pow(T,3) - 380*pow(T,2) + 4100*T + 220;
vel = -0.48*pow(T,3) + 36*pow(T,2) - 760*T + 4100;
if(alt > max_alt)
{
max_alt = alt;
max_time_of_alt = T;
};
fprintf(balloon,"%.3lf %.3lf %.3lf\n", T, alt, vel/3600);
}
fprintf(balloon, "\nmax alitude: %.3lf m\n", max_alt);
fprintf(balloon, "\ntime of max alitude: %.3lf hrs\n", max_time_of_alt);

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

}

Wednesday, September 19, 2018

Homework 7

Factorials
/* This program compares a recursive function and */
/* a nonrecursive function for computing factorials. */
#include <stdio.h>
#include <math.h>
int main(void)
#define PI 3.141593
#define e 2.718281
{
/* Declare variables and function prototypes. */
double n;
double factorial(double k);
double factorial_r(double k);
double n_fact(double k);
/* Get user input. */
printf("Enter positive integer: \n");
scanf("%lf",&n);
/* Compute and print factorials. */
printf("Nonrecursive: %lf! = %lf \n",n,factorial(n));
printf("Recursive: %lf! = %lf \n",n,factorial_r(n));
printf("Sterling: %lf! = %lf \n",n,n_fact(n));
/* Exit program. */
return 0;
}
/* This function computes a factorial with a loop. */
double factorial(double k)
{
/* Declare variables. */
double j;
long term;
/* Compute factorial with multiplication. */
term = 1;
for (j=2; j<=k; j++)
term *=j;
/* Return factorial value. */
return term;
}
/* This function computes a factorial recursively. */
double factorial_r(double k)
{
/* Use recursive reference until k=0. */
if (k == 0)
return 1;
else
return k*factorial_r(k-1);
}
/* This function computes a factorial using Sterling Formula*/
double n_fact(double n)
{
return sqrt(2*PI*n)*pow(n/e, n);
}

Random Dice Rolls
/* This program generates and prints ten random */
/* integers between user-specified limits. */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/* Declare variables and function prototype. */
unsigned int seed;
int a=1, b=6, k, dice1, dice2, d;
double dice_percent, dicecounter;
int rand_int(int a,int b);
/* Get seed value and interval limits. */
printf("Enter a positive integer seed value: \n");
scanf("%u",&seed);
printf("Enter the number of rolls of the dice to simulate: \n");
scanf("%u",&d);
srand(seed);
/* Generate and print ten random numbers. */
printf("\nRandom dice rolls of two dice: \n");
for (k=1; k<=d; k++)
{
dice1 = rand_int(a,b);
dice2 = rand_int(a,b);
if (dice1 + dice2 == 8)
{
dicecounter++;
}
printf("\nRoll #%i: %i, %i\n", k , dice1, dice2);
}
dice_percent = (dicecounter / d) * 100;
printf("\nPercentage of times that the values of the dice equaled 8: %.2f ", dice_percent);
/* Exit program. */
return 0;
}
/* This function generates a random integer */
/* between specified limits a and b (a<b). */
int rand_int(int a,int b)
{
return rand()%(b-a+1) + a;
}

Wednesday, September 12, 2018

Homework 5

/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* 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);
}

}

Tuesday, September 11, 2018

Homework 3

Linear Interpolate Seawater Temperatures from Salinity

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("\nEnter first salinity and freezing temperature: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);
/* Print new freezing temperature. */
printf("\nNew freezing temperature in degrees F: %4.3f \n",f_b);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Linear Interpolation of Seawater Temperatures in Centigrade

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c, f_b_centigrade;
/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("Enter first salinity and freezing temperature: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);
f_b_centigrade = (f_b - 32)/1.8;

/* Print new freezing temperature. */
printf("New freezing temperature in degrees C: %4.3lf \n", f_b_centigrade);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Linear Interpolation of Salinity

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the salinity of seawater at a certain temperature */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */
printf("Use ppt for temperature values. \n");
printf("Use degrees F for temperatures. \n");
printf("\nEnter first freezing temperature and then salinity: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second freezing temperature and then salinity: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new temperature: \n");
scanf("%lf",&b);

// Use linear interpolation to compute new salinity.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);

/* Print new salinity. */
printf("\nNew salinity in parts per tenths: %4.2f \n",f_b);
return 0;
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Bouncy Buttons Lab

const int LED_9 = 9; //The LED is connected to pin 9 
const int BUTTON_2 = 2; //The Button is connected to pin 2 
const int LED_8 = 8; //The LED is connected to pin 9 
const int BUTTON_3 = 3; //The Button is connected to pin 2
 boolean lastButton_2 = LOW; //Variable containing the previous button state 
boolean currentButton_2 = LOW; //Variable containing the current button state 
boolean ledOn_9 = false; //The present state of the LED (on/off) 
boolean lastButton_3 = LOW; //Variable containing the previous button state 
boolean currentButton_3 = LOW; //Variable containing the current button state 
boolean ledOn_8 = false; //The present state of the LED (on/off) 

void setup() 
pinMode (LED_9, OUTPUT); //Set the LED pin as an output 
pinMode (BUTTON_2, INPUT); //Set button as input (not required) 
pinMode (LED_8, OUTPUT); //Set the LED pin as an output 
pinMode (BUTTON_3, INPUT); //Set button as input (not required) }

 /* Debouncing Function Pass it the previous button state, * and get back the current debounced button state.*/ 

boolean debounce_9(boolean last_9) 
   { 
      boolean current_9 = digitalRead(BUTTON_2); //Read the button state 
         if (last_9 != current_9) //if it's different… 
      { 
         delay(5); //wait 5ms 
         current_9 = digitalRead(BUTTON_2); //read it again 
         return current_9; //return the current value 
      }
    } 

boolean debounce_8(boolean last_8) 
   { 
      boolean current_8 = digitalRead(BUTTON_3); //Read the button state 
         if (last_8 != current_8) //if it's different… 
      { 
         delay(5); //wait 5ms 
        current_8 = digitalRead(BUTTON_3); //read it again 
        return current_8; //return the current value 
      }
    } 

void loop() 
currentButton_2 = debounce_9(lastButton_2); //read debounced state 
if (lastButton_2 == LOW && currentButton_2 == HIGH) //if it was pressed... 
ledOn_9 = !ledOn_9; //toggle the LED value } 
lastButton_2 = currentButton_2; //reset button value 
digitalWrite(LED_9, ledOn_9); //change the LED state 
currentButton_3 = debounce_8(lastButton_3); //read debounced state 
if (lastButton_3 == LOW && currentButton_3 == HIGH) //if it was pressed... 
ledOn_8 = !ledOn_8; //toggle the LED value 
lastButton_3 = currentButton_3; //reset button value 
digitalWrite(LED_8, ledOn_8); //change the LED state 
}

Homework 2

Height Estimates from in to ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates. */
femur_ht_f = (femur*1.94 + 28.7) / 12;
femur_ht_m = (femur*1.88 + 32) / 12;
humerus_ht_f = (humerus*2.8 + 28.2) / 12;
humerus_ht_m = (humerus*2.9 + 27.9) / 12;
/* Print height estimates. */

printf("\nHeight Estimates in Feet \n");
printf("\nFemur Female Estimate: %5.1f ft\n",femur_ht_f);
printf("Femur Male Estimate: %5.1f ft\n",femur_ht_m);
printf("\nHumerus Female Estimate: %5.1f ft\n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f ft\n",humerus_ht_m);

/* Exit program. */
return 0;
}


Height Estimates in ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */

printf("Enter Values in Feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates. */
femur_ht_f = ((femur*1.94*12) + 28.7)/12;
femur_ht_m = ((femur*1.88*12) + 32)/12;
humerus_ht_f = ((humerus*2.8*12) + 28.2)/12;
humerus_ht_m = ((humerus*2.9*12) + 27.9)/12;

/* Print height estimates. */
printf("\nHeight Estimates in Feet \n");
printf("\nFemur Female Estimate: %5.1f ft\n",femur_ht_f);
printf("Femur Male Estimate: %5.1f ft\n",femur_ht_m);
printf("\nHumerus Female Estimate: %5.1f ft\n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f ft\n",humerus_ht_m);

/* Exit program. */
return 0;
}

Height Estimates in in and ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)

{
/* Declare variables. */
double femur, humerus, femur_ht_f_in, femur_ht_m_in, humerus_ht_f_in,
humerus_ht_m_in, femur_ht_f_ft, femur_ht_m_ft, humerus_ht_f_ft,
humerus_ht_m_ft;

/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates in inches. */
femur_ht_f_in = (femur*1.94 + 28.7);
femur_ht_m_in = (femur*1.88 + 32);
humerus_ht_f_in = (humerus*2.8 + 28.2);
humerus_ht_m_in = (humerus*2.9 + 27.9);

/* Compute height estimates in feet. */
femur_ht_f_ft = (femur*1.94 + 28.7) / 12;
femur_ht_m_ft = (femur*1.88 + 32) /12;
humerus_ht_f_ft = (humerus*2.8 + 28.2) / 12;
humerus_ht_m_ft = (humerus*2.9 + 27.9) / 12;

/* Print height estimates. */
printf("\nHeight Estimates in Inches and also Feet\n");
printf("\nFemur Female Estimate: %5.1f in /%5.2f ft \n", femur_ht_f_in, femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f in /%5.2f ft \n", femur_ht_m_in, femur_ht_m_ft);
printf("\nHumerus Female Estimate: %5.1f in /%5.2f ft\n", humerus_ht_f_in, humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f in /%5.2f ft\n", humerus_ht_m_in, humerus_ht_m_ft);

/* Exit program. */
return 0;
}

Height Estimates in in/ft based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur_in, femur_ft, humerus_in, humerus_ft, femur_ht_f_in, femur_ht_m_in, humerus_ht_f_in,
humerus_ht_m_in, femur_ht_f_ft, femur_ht_m_ft, humerus_ht_f_ft,
humerus_ht_m_ft;

/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur_in);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_in);
printf("\nEnter Values in Feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur_ft);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_ft);

/* Compute height estimates in inches. */
femur_ht_f_in = (femur_in*1.94 + 28.7);
femur_ht_m_in = (femur_in*1.88 + 32);
humerus_ht_f_in = (humerus_in*2.8 + 28.2);
humerus_ht_m_in = (humerus_in*2.9 + 27.9);

/* Compute height estimates in feet. */
femur_ht_f_ft = ((femur_ft*12)*1.94 + 28.7);
femur_ht_m_ft = ((femur_ft*12)*1.88 + 32);
humerus_ht_f_ft = ((humerus_ft*12)*2.8 + 28.2);
humerus_ht_m_ft = ((humerus_ft*12)*2.9 + 27.9);

/* Print height estimates. */
printf("\nHeight Estimates in Inches and then Feet\n");
printf("\nFemur Female Estimate: %5.1f in / %5.2f ft \n", femur_ht_f_in, femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f in / %5.2f ft \n", femur_ht_m_in, femur_ht_m_ft);
printf("\nHumerus Female Estimate: %5.1f in / %5.2f ft\n", humerus_ht_f_in, humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f in / %5.2f ft\n", humerus_ht_m_in, humerus_ht_m_ft);

/* Exit program. */
return 0;
}

Height Estimates in cm based on Bone Lengths

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double femur, humerus, femur_ht_f, femur_ht_m, humerus_ht_f, humerus_ht_m;

/* Get user input from the keyboard. */
printf("Enter Values in Centimeters. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);

/* Compute height estimates in centimeters. */
femur_ht_f = ((femur/2.54)*1.94 + 28.7);
femur_ht_m = ((femur/2.54)*1.88 + 32);
humerus_ht_f = ((humerus/2.54)*2.8 + 28.2);
humerus_ht_m = ((humerus/2.54)*2.9 + 27.9);

/* Print height estimates. */
printf("\nHeight Estimates in Centimeters\n");
printf("\nFemur Female Estimate: %5.2f cm\n", femur_ht_f*2.54);
printf("Femur Male Estimate: %5.2f cm\n", femur_ht_m*2.54);
printf("\nHumerus Female Estimate: %5.2f cm\n", humerus_ht_f*2.54);
printf("Humerus Male Estimate: %5.2f cm\n", humerus_ht_m*2.54);

/* Exit program. */
return 0;
}

Molecular weight of glycine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_glycine;

/* Compute weight of glycine. */
weight_glycine = 2*oxygen + 2*carbon + nitrogen + 5*hydrogen;

/* Print weight. */
printf("The molecular weight for Glycine is %.4lf amu.", weight_glycine);

/* Exit program. */
return 0;
}

Molecular Weights of Glutamic and Glutamine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_glutamic, weight_glutamine;

/* Compute weight of glutamic and glutamine. */
weight_glutamic = 4*oxygen + 5*carbon + nitrogen + 8*hydrogen;
weight_glutamine = 3*oxygen + 5*carbon + 2*nitrogen + 10*hydrogen;

/* Print weight. */
printf("The molecular weight for Glutamic is %.4lf amu.\n", weight_glutamic);
printf("\nThe molecular weight for Glutamine is %.4lf amu.", weight_glutamine);

/* Exit program. */
return 0;
}

Molecular Weight of am Amino Acid

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, weight_amino, o_num, c_num, n_num, s_num, h_num;

/*Input number of atoms of amino acid*/
printf("Enter the number of atoms for each element of your amino acid. \n");
printf("Enter number of oxygen atoms: \n");
scanf("%lf",&o_num);
printf("Enter number of carbon atoms: \n");
scanf("%lf",&c_num);
printf("Enter number of nitrogen atoms: \n");
scanf("%lf",&n_num);
printf("Enter number of sulfur atoms: \n");
scanf("%lf",&s_num);
printf("Enter number of hydrogen atoms: \n");
scanf("%lf",&h_num);

/* Compute weight of amino acid. */

weight_amino = (o_num*oxygen) + (c_num*carbon) + (n_num*nitrogen) + (s_num*sulfur) + (h_num*hydrogen);

/* Print weight. */
printf("\nThe molecular weight for your amino acid is %.4lf amu.", weight_amino);

/* Exit program. */
return 0;
}

Average Weight of Elements of Amino Acid

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare variables. */
double oxygen=15.9994, carbon=12.011, nitrogen=14.00674, sulfur=32.066, hydrogen=1.00794, o_num, c_num, n_num, s_num, h_num, sum_atoms, average_weight;

/*Input number of atoms of amino acid*/
printf("Enter the number of atoms for each element of your amino acid. \n");
printf("Enter number of oxygen atoms: \n");
scanf("%lf",&o_num);
printf("Enter number of carbon atoms: \n");
scanf("%lf",&c_num);
printf("Enter number of nitrogen atoms: \n");
scanf("%lf",&n_num);
printf("Enter number of sulfur atoms: \n");
scanf("%lf",&s_num);
printf("Enter number of hydrogen atoms: \n");
scanf("%lf",&h_num);

/* Compute weight of amino acid. */
sum_atoms = o_num + c_num + n_num + s_num + h_num;

average_weight = ((o_num*oxygen) + (c_num*carbon) + (n_num*nitrogen) + (s_num*sulfur) + (h_num*hydrogen)) / sum_atoms;

/* Print weight. */
printf("\nThe average weight of the elements for your amino acid is %.4lf amu.", average_weight);

/* Exit program. */
return 0;
}

Kitt Nightrider Blinking

void setup()
{
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT); //Initialize Pins
}
void loop()
{
digitalWrite(10,HIGH); //Set the LED
On delay(100); //Wait for 100 ms
digitalWrite(10,LOW); //Set the LED Off

digitalWrite(9,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(9,LOW); //Set the LED Off

digitalWrite(8,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(8,LOW); //Set the LED Off

digitalWrite(7,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(7,LOW); //Set the LED Off

digitalWrite(6,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(6,LOW); //Set the LED Off

digitalWrite(7,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(7,LOW); //Set the LED Off

digitalWrite(8,HIGH); //Set the LED On
delay(100); //Wait for 100 msms
digitalWrite(8,LOW); //Set the LED Off

digitalWrite(9,HIGH); //Set the LED On
delay(100); //Wait for 100 ms
digitalWrite(9,LOW); //Set the LED Off

Homework 1

Meters to Miles

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double dist_meter, dist_mile;

/* Get user input from the keyboard. */
printf("Enter distance in meters: \n");
scanf("%lf",&dist_meter);

/* Convert meter to miles*/
dist_mile = dist_meter * 0.000621371;
printf("\n%lf meters is equivalent to %lf miles\n", dist_meter, dist_mile);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Convert Celsius to Rankine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double celsius, fahrenheit, rankine;

/* Get user input from the keyboard. */
printf("Enter temperature in Celsius: \n");
scanf("%lf",&celsius);

/* Convert celsius to rankine*/
fahrenheit = celsius * 9/5 + 32;
rankine = fahrenheit + 459.67;
printf("\n%lf Celsius is equivalent to %lf Rankine \n", celsius, rankine);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Ellipse
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare and initialize variables. */
double semi_major, semi_minor, area_ellipse;

#define PI 3.141593
/* Get user input from the keyboard. */
printf("Enter values in meters to calculate area of an ellipse.\n");
printf("\nEnter length of semiaxis a: \n");
scanf("%lf",&semi_major);
printf("Enter length of semiaxis b: \n");
scanf("%lf", &semi_minor);

/* Compute area of ellipse*/
area_ellipse = PI * semi_major * semi_minor;
printf("\nThe area of the ellipse is %lf meters squared\n", area_ellipse);
/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Sector of a Cirle

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double angle_sector, radius, area_sector;
#define PI 3.141593

/* Get user input from the keyboard. */
printf("Enter value in meters to calculate area of a sector.\n");
printf("Enter length of radius of your circle: \n");
scanf("%lf",&radius);
printf("\nEnter value in degrees for angle of a sector.\n");
printf("Enter angle of your sector: \n");
scanf("%lf", &angle_sector);

/* Compute area of sector*/
area_sector = (angle_sector / 360) * (PI * radius * radius);
printf("\nThe area of the sector is %lf meters squared.\n", area_sector);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/