Saturday, March 4, 2017

Day 2

Day 2


On day 2 lab was to build an LED circuit and get it to function like the K.I.T.T. car from the Knight Rider TV series. The materials used are; breadboard, 4 resistors, 6 wires, 4 LED's, an arduino, and a computer.


This is the arduino used from day 1 that will be used to program our circuit.


The C syntax for calculating energy of an object in motion through a ramp.


The C syntax for centripetal acceleration, potential energy, and change in potential energy from left to right.


The completed LED circuit. Here the red wire is the one that is responsible for bringing in power to the circuit, also is the grounded wire, and the resistors are there so that the circuit doesn't have too much current running through it, which could destroy the circuit board.


Practicing increment and decrement operators.


Practicing the printf command to return a value of printable characters.


Exercise to determine the height of a person using forensics based on their femur or humerus heights.


The circuit here was programmed to turn on from the red light to the yellow light and come back to red, to mimic the K.I.T.T car's effect.


Blue light next in series.


Green light actuates after the blue light.


Yellow light activates last in the series, where it will then go back to the red light.


K.I.T.T. Car from the Knight Rider.

Homework
#1 Program a function to convert meters to miles.

/*--------------------------------------------------------*/
/* Program Chapter1_1                                     */
/*                                                        */
/* this program computes the                              */
/* distance in meters to miles.                           */
#include <stdio.h>
#include <math.h>
int main(void)
{
    /* Declare and initialize variables. */
    double x1=1000, miles;
    /* compute miles. */
    miles=x1/(1609);
    /* Print distance. */
    printf ("The distance in miles is"
    "%5.2f\n",miles);
    /* Exit program. */
    return 0;
}
/*---------------------------------------------------------*/

#2 Program a function that converts Celsius to Rankine.

/*--------------------------------------------------------*/
/* Program Chapter1_2                                     */
/*                                                        */
/* this program computes the                              */
/* degrees in Rankine.                                    */
#include <stdio.h>
#include <math.h>
int main(void)
{
    /* Declare and initialize variables. */
    double x1=100, Rankine;
    /* compute Rankine. */
    Rankine=(x1+273)*(5/9);
    /* Print Rankine. */
    printf ("The degrees in Rankine is %5.2f\n",Rankine);
    /* Exit program. */
    return 0;
}
/*---------------------------------------------------------*/

#3 Program a function that calculates the area of an ellipse.

/*--------------------------------------------------------*/
/* Program Chapter1_3                                     */
/*                                                        */
/* this program computes the                              */
/* area of an ellipse.                                    */
#include <stdio.h>
#include <math.h>
int main(void)
{
    /* Declare and initialize variables. */
    double x1=1, y1=2, Area;
    /* compute Area. */
    Area=(x1*y1)*(22/7);
    /* Print Area. */
    printf ("The area of the ellipse is"
    "%5.2f\n",Area);
    /* Exit program. */
    return 0;
}
/*---------------------------------------------------------*/

#4 Program a function that calculates the area of a sector of a circle.

/*--------------------------------------------------------*/
/* Program Chapter1_4                                     */
/*                                                        */
/* this program computes the                              */
/* area of a sector of a circle.                          */
#include <stdio.h>
#include <math.h>
int main(void)
{
    /* Declare and initialize variables. */
    double x1=10, d1=60, Area;
    /* compute Area. */
    Area=(d1*2*22/7*x1*x1)/360;
    /* Print Area. */
    printf ("The area of the sector is "
    "%5.2f\n",Area);
    /* Exit program. */
    return 0;
}
/*---------------------------------------------------------*/

#5 Program a function that gives the height of a man or woman based on humerus and femur length.

/*-----------------------------------------------------*/
/* Program chapter1_5                                  */
/*                                                     */
/* this program computes the                           */
/* hight of the human                                  */
#include<stdio.h>
#include<math.h>

int main()
{
    /* Declare of variables. */
    double Female_height_femur, Female_height_humorus, Male_height_femur, Male_height_humorus, length;
    /* compute the height. */
    scanf("%lf",&length);
    Female_height_femur=length*1.94+28.7;
    Female_height_humorus=length*2.8+28.2;
    Male_height_femur=length*1.94+32;
    Male_height_humorus=length*2.9+27.9;
    /* Print height. */
printf("%5.2f %5.2f %5.2f %5.2f\n", Female_height_femur, Female_height_humorus, Male_height_femur, Male_height_humorus);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#6 Program the Arduino to cause the LED's to flicker like the K.I.T.T. car.

void setup() {
pinMode(10,OUTPUT); //Initialize Pin
pinMode(8,OUTPUT); //Initialize Pin
pinMode(6,OUTPUT); //Initialize Pin
pinMode(4,OUTPUT); //Initialize Pin
}
void loop() {
digitalWrite(10,HIGH); //Set the LED On
delay(100); //Wait for 1000 ms
digitalWrite(10,LOW); //Set the LED Off
delay(10); //Wait for 1 second

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

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

digitalWrite(4,HIGH); //Set the LED On
delay(100); //Wait for 1000 ms
digitalWrite(4,LOW); //Set the LED Off
delay(10); //Wait for 1 second

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

digitalWrite(8,HIGH); //Set the LED On
delay(100); //Wait for 1000 ms
digitalWrite(8,LOW); //Set the LED Off
delay(10); //Wait for 1 second
}

#7

/*-----------------------------------------------------*/
/* Program chapter1_5                                  */
/*                                                     */
/* this program computes the                           */
/* hight of the human                                  */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Female_height_femur, Female_height_humerus, Male_height_femur, Male_height_humerus,
    Female_femur_feet, Female_humerus_feet, Male_femur_feet, Male_humerus_feet, humerus_feet, femur_feet,
    femur_inches, humerus_inches;
    /* compute the height. */
    scanf("%f",&femur_feet);
    scanf("%f",&humerus_feet);
    femur_inches=femur_feet*12;
    humerus_inches=humerus_feet*12;
    Female_height_femur=femur_inches*1.94+28.7;
    Female_height_humerus=humerus_inches*2.8+28.2;
    Male_height_femur=femur_inches*1.94+32;
    Male_height_humerus=humerus_inches*2.9+27.9;
    Female_femur_feet=Female_height_femur/12;
    Female_humerus_feet=Female_height_humerus/12;
    Male_femur_feet=Male_height_femur/12;
    Male_humerus_feet=Male_height_humerus/12;
    /* Print height. */
printf("Female height by femer size - " "%5.2f feet. \n", Female_femur_feet);
printf("Female height by humerus size - " "%5.2f feet. \n",Female_humerus_feet);
printf("Male height by femer size - " "%5.2f feet. \n", Male_femur_feet);
printf("Male height by humerus size - " "%5.2f feet. \n", Male_humerus_feet);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#8

/*-----------------------------------------------------*/
/* Program chapter1_5                                  */
/*                                                     */
/* this program computes the                           */
/* hight of the human                                  */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Female_height_femur, Female_height_humerus, Male_height_femur, Male_height_humerus,
    Female_femur_centimeters, Female_humerus_centimeters, Male_femur_centimeters, Male_humerus_centimeters,
    humerus_centimeters, femur_centimeters, femur_inches, humerus_inches;
    /* compute the height. */
    scanf("%f",&femur_centimeters);
    scanf("%f",&humerus_centimeters);
    femur_inches=femur_centimeters/2.54;
    humerus_inches=humerus_centimeters/2.54;
    Female_height_femur=femur_inches*1.94+28.7;
    Female_height_humerus=humerus_inches*2.8+28.2;
    Male_height_femur=femur_inches*1.94+32;
    Male_height_humerus=humerus_inches*2.9+27.9;
    Female_femur_centimeters=Female_height_femur*2.54;
    Female_humerus_centimeters=Female_height_humerus*2.54;
    Male_femur_centimeters=Male_height_femur*2.54;
    Male_humerus_centimeters=Male_height_humerus*2.54;
    /* Print height. */
printf("Female height by femer size - " "%5.2f centimeters. \n", Female_femur_centimeters);
printf("Female height by humerus size - " "%5.2f centimeters. \n",Female_humerus_centimeters);
printf("Male height by femer size - " "%5.2f centimeters. \n", Male_femur_centimeters);
printf("Male height by humerus size - " "%5.2f centimeters. \n", Male_humerus_centimeters);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#8

/*-----------------------------------------------------*/
/* Program chapter1_6                                  */
/*                                                     */
/* this program computes the                           */
/* molecular weight of molecules                       */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Oxygen, Carbon, Nitrogen, Sulfur, Hydrogen, glycine, glutamic, glutamine, amino_acid;
    /* compute the weight. */
    Oxygen=15.9994, Carbon=12.011, Nitrogen=14.00674, Sulfur=32.066, Hydrogen=1.00794;
     glycine=2*Oxygen+2*Carbon+1*Nitrogen+0*Sulfur+5*Hydrogen;
     /* Print weight. */
     printf("The molecular weight of glycine is ""%5.2f AMU. \n",glycine);
     /* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#9

/*-----------------------------------------------------*/
/* Program chapter1_6                                  */
/*                                                     */
/* this program computes the                           */
/* molecular weight of molecules                       */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Oxygen, Carbon, Nitrogen, Sulfur, Hydrogen, number_of_oxygen_atoms, number_of_carbon_atoms,
    number_of_nitrogen_atoms, number_of_sulfur_atoms, number_of_hydrogen_atoms,
    glycine, glutamic, glutamine, amino_acid;
    /* compute the weight. */
    scanf("%f",&number_of_oxygen_atoms);
    scanf("%f",&number_of_carbon_atoms);
    scanf("%f",&number_of_nitrogen_atoms);
    scanf("%f",&number_of_sulfur_atoms);
    scanf("%f",&number_of_hydrogen_atoms);
    Oxygen=15.9994, Carbon=12.011, Nitrogen=14.00674, Sulfur=32.066, Hydrogen=1.00794;
    amino_acid=number_of_oxygen_atoms*Oxygen+number_of_carbon_atoms*Carbon+
    number_of_nitrogen_atoms*Nitrogen+number_of_sulfur_atoms*Sulfur+number_of_hydrogen_atoms*Hydrogen;
     /* Print weight. */
     printf("The molecular weight of this amino acid is ""%5.2f g/mol. \n",amino_acid);
     /* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#10

/*-----------------------------------------------------*/
/* Program chapter1_6                                  */
/*                                                     */
/* this program computes the                           */
/* molecular weight of molecules                       */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Oxygen, Carbon, Nitrogen, Sulfur, Hydrogen, number_of_oxygen_atoms, number_of_carbon_atoms,
    number_of_nitrogen_atoms, number_of_sulfur_atoms, number_of_hydrogen_atoms,
    glycine, glutamic, glutamine, amino_acid, Average_molecular_weight;
    /* compute the weight. */
    scanf("%f",&number_of_oxygen_atoms);
    scanf("%f",&number_of_carbon_atoms);
    scanf("%f",&number_of_nitrogen_atoms);
    scanf("%f",&number_of_sulfur_atoms);
    scanf("%f",&number_of_hydrogen_atoms);
    Oxygen=15.9994, Carbon=12.011, Nitrogen=14.00674, Sulfur=32.066, Hydrogen=1.00794;
    amino_acid=number_of_oxygen_atoms*Oxygen+number_of_carbon_atoms*Carbon+
    number_of_nitrogen_atoms*Nitrogen+number_of_sulfur_atoms*Sulfur+number_of_hydrogen_atoms*Hydrogen;
    Average_molecular_weight=amino_acid/(number_of_oxygen_atoms+number_of_carbon_atoms+
    number_of_nitrogen_atoms+number_of_sulfur_atoms+number_of_hydrogen_atoms);
     /* Print weight. */
     printf("The molecular weight of this amino acid is ""%5.2f g/mol#ofatoms. \n",Average_molecular_weight);
     /* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

#11

/*-----------------------------------------------------*/
/* Program chapter1_6                                  */
/*                                                     */
/* this program computes the                           */
/* molecular weight of molecules                       */
#include<stdio.h>
#include<math.h>

int main() 
{
    /* Declare of variables. */
    float Oxygen, Carbon, Nitrogen, Sulfur, Hydrogen, number_of_oxygen_atoms, number_of_carbon_atoms,
    number_of_nitrogen_atoms, number_of_sulfur_atoms, number_of_hydrogen_atoms,
    glycine, glutamic, glutamine, amino_acid, Average_molecular_weight;
    /* compute the weight. */
    scanf("%f",&number_of_oxygen_atoms);
    scanf("%f",&number_of_carbon_atoms);
    scanf("%f",&number_of_nitrogen_atoms);
    scanf("%f",&number_of_sulfur_atoms);
    scanf("%f",&number_of_hydrogen_atoms);
    Oxygen=15.9994, Carbon=12.011, Nitrogen=14.00674, Sulfur=32.066, Hydrogen=1.00794;
    amino_acid=number_of_oxygen_atoms*Oxygen+number_of_carbon_atoms*Carbon+
    number_of_nitrogen_atoms*Nitrogen+number_of_sulfur_atoms*Sulfur+number_of_hydrogen_atoms*Hydrogen;
    Average_molecular_weight=amino_acid/(number_of_oxygen_atoms+number_of_carbon_atoms+
    number_of_nitrogen_atoms+number_of_sulfur_atoms+number_of_hydrogen_atoms);
     /* Print weight. */
     printf("The average molecular weight of this amino acid is ""%5.2f g/mol#ofatoms. \n",Average_molecular_weight);
     /* Exit program. */
return 0;
}
/*-----------------------------------------------------*/

No comments:

Post a Comment