Tuesday, March 7, 2017

Introduction to Microcontrollers lab


                                             Introduction to Microcontrollers lab 2

We got introduce to  Microcontrollers that is a  low-cost integrated circuit that contains memory, processing units, and input/output circuitry in a single unit. The Microcontroller is used in many objects of our daily life, like microwaves and modern cars. The brand of the Microcontroller that we use is a cheaper version of Arduino. Furthermore, in this lab, we learn how to install the Programming Environment for the chip and we use  Arduino.exe to created a program to make at least 4 LEDs flash blink. 

Materials:
  • Arduino Board
  •   Breadboard
  •  Sufficient Wire 
  •  4LEDs and 4resistors between 200 –500 Ohms. (Red Red Brown is 220 and ideal) 

*Breadboard is a simpler way to be able to connect wire together

Put Together:
The GND on the breadboard should be connected to the Pin marked GND.  A wire connected to the positive end of the LED should connect to Pin 10 as shown at right.  Use a ~220  resistor to limit current to the LED. 

Program: 


void setup() {
pinMode(10,OUTPUT); //Initialize Pin
pinMode(9,OUTPUT); //Initialize Pin
pinMode(8,OUTPUT); //Initialize Pin
pinMode(6,OUTPUT); //Initialize Pin
}
void loop() {
 //red
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

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

//green
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

//blue
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

//back

//GREEN
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

//YELLOW

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

}





     

-------------









Class activities 

We tried to write a program that will define g as gravity to be 9.81 by assigning it to an identifier, In this case, the g was assigned to the formula. Also, we wrote how the differences of z = x++*y; (will add one with x first them multip. y) and z = ++x*y; (will multiply first then add one).


 Furthermore, in a bone height problem,  we show how the inputs to the program are the lengths of the two bones, and the outputs are the heights determined from each of the inputs. And because we don't if the bone are female or male the computer will estimate the height.



We also wrote the steps on how to build a program for the bone height problem.


Height estimates from bone lengths program:

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
printf("Enter length of fermur in inches\n");
scanf("%f ",&femurlenght);
printf("Enter length of hurmerus in inches\n\n");
scanf("%f ",&hurmeruslength);
// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;
//  Print the height estimates

printf("Male heigth:\n\n");
 printf ("Femur: %6.2f in  \n",malef );
 printf("Humer: %6.2f in \n\n", maleh);

printf("Female heigth:\n\n");
 printf ("Femur: %6.2f in  \n",femalef );
 printf("Humer: %6.2f in \n", femaleh);

}
 ----------
Homework



Height estimates from bone lengths.:
1)  Modify the program so that it converts the output values from inches to feet. The input would still be entered in inches. Use a single value for the output, such as 6.5 feet.

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
printf("Enter length in inches\n");

scanf("%f",&femurlenght);
printf("Fermur:%.1f in\n",femurlenght);
scanf("%f",&hurmeruslength);
printf("Hurmerus:%.1f in \n\n",hurmeruslength);
// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;

// Print the height estimates
//conver inches into feet
printf("Male heigth:\n\n");
 printf ("Femur: %6.2f ft \n",malef/12 );
 printf("Humer: %6.2f ft\n\n", maleh/12);

printf("Female heigth:\n\n");
 printf ("Femur: %6.2f ft  \n",femalef/12 );
 printf("Humer: %6.2f ft \n", femaleh/12);

}



2) Modify the program so that it asks the user to enter the values in feet. The program would then need to convert the values in feet to centimeters before doing the computations. The output would also print the output heights in feet, as in 6.5 feet.

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
printf("Enter length in feet\n");

scanf("%f",&femurlenght);
scanf("%f",&hurmeruslength);
printf("Fermur:%.1f ft \n", femurlenght/12);
printf("Hurmerus:%.1f ft\n\n",hurmeruslength/12);

//conver feet into centimeters
 femurlenght=femurlenght*30.5/12 ;
printf("Fermur:%.1f cm \n", femurlenght);
hurmeruslength=hurmeruslength*30.5/12;
printf("Hurmerus:%.1f cm\n\n",hurmeruslength);

// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;

//  Print the height estimates

printf("Male heigth:\n\n");
 printf ("Femur: %.1f ft \n",malef/30.5 );
 printf("Humer: %.1f ft\n\n", maleh/30.5);

printf("Female heigth:\n\n");
 printf ("Femur: %.1f ft  \n",femalef/30.5);
 printf("Humer: %.1f ft \n", femaleh/30.5);

}

3) Modify the program so that it reads the input values in inches and then estimates the output heights using feet and inches. (Note that you are printing two output values for each height estimate.)

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
printf("Enter length in inches\n");

scanf("%f",&femurlenght);
scanf("%f",&hurmeruslength);
printf("Fermur:%.1f IN \n", femurlenght);
printf("Hurmerus:%.1f IN\n\n",hurmeruslength);


// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;


//  Print the height estimates

printf("Male heigth:\n\n");
 printf("Femur:%6.2f ft \n", malef/12);//conver inches into feet
  printf("Femur:%6.2f in \n",malef);
 printf("Humer:%6.2f ft\n", maleh/12);//conver inches into feet
  printf("Humer:%6.2f in\n\n",maleh);

printf("Female heigth:\n\n");
 printf ("Femur:%6.2f ft  \n",femalef/12);//conver inches into feet
  printf("Femur:%6.2f in \n",femalef);
 printf("Humer:%6.2f ft \n", femaleh/12);//conver inches into feet
  printf("Humer:%6.2f in\n\n",femaleh);
}

4)Modify the program so that it reads the input values in feet and inches, and then estimates the output heights using feet and inches. (Note that you are reading two input values for each bone and you are printing two output values for each height estimate.) 

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
printf("Enter length in inches and feet\n");

scanf("%f",&femurlenght);
scanf("%f",&hurmeruslength);
printf("Fermur:%.1f IN \n", femurlenght);
printf("Hurmerus:%.1f IN\n\n",hurmeruslength);

scanf("%f",&femurlenght);
scanf("%f",&hurmeruslength);
printf("Fermur:%.1f ft \n", femurlenght/12);
printf("Hurmerus:%.1f ft\n\n",hurmeruslength/12);
// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;


//  Print the height estimates

printf("Male heigth:\n\n");
 printf("Femur:%6.2f ft \n", malef/12);//conver inches into feet
  printf("Femur:%6.2f in \n",malef);
 printf("Humer:%6.2f ft\n", maleh/12);//conver inches into feet
  printf("Humer:%6.2f in\n\n",maleh);

printf("Female heigth:\n\n");
 printf ("Femur:%6.2f ft  \n",femalef/12);//conver inches into feet
  printf("Femur:%6.2f in \n",femalef);
 printf("Humer:%6.2f ft \n", femaleh/12);//conver inches into feet
  printf("Humer:%6.2f in\n\n",femaleh);

}

5) Modify the program so that it reads the bone values in centimeters and outputs the height estimates in centimeters. (Recall that 1 in = 2.54 cm.)

#include<stdio.h>
#include <math.h>

int main(void) {
    float femurlenght,hurmeruslength,malef,maleh,femalef,femaleh;
// Read the  lengths of the femur and the humerus
scanf("%f",&femurlenght);
scanf("%f",&hurmeruslength);
//conver bone values from inches to cm
printf(" ENTER VALUES IN CM \n");
printf("Fermur:%6.2f cm\n", femurlenght*2.54);
printf("Hurmerus:%6.2f cm\n\n",hurmeruslength*2.54);

// compute the height estimates
//male
malef= femurlenght*1.88 + 32;
maleh= hurmeruslength*2.9 + 27.9;

//female
femalef= femurlenght*1.94 + 28.2;
femaleh= hurmeruslength*2.8 + 27.9;

//  Print the height estimates
//----conver inches into feet
printf("Male heigth:\n\n");
 printf ("Femur: %6.2f cm \n",malef*2.54);
 printf("Humer: %6.2f cm\n\n", maleh*2.54);

printf("Female heigth:\n\n");
 printf ("Femur: %6.2f cm \n",femalef*2.54 );
 printf("Humer: %6.2f  cm\n", femaleh*2.54);

}


Amino Acid Molecular Weights:

1. Write a program to compute and print the molecular weight of glycine.

#include <stdio.h>
#include <math.h>
#define O 15.9994
#define C 12.011
#define N 14.00674
#define S 32.066
#define H 1.00794
int main(void){
float molecularw;
int Oxygen,Nitrogen,Carbon,Sulfur,Hydrogen;
scanf("%i %i %i %i %i", &Oxygen, &Carbon, &Nitrogen, &Sulfur, &Hydrogen);

// input the numer of atoms
printf ("Enter number of atoms:\n");
printf ("Oxygen:%i \n",Oxygen);
printf ("Carbon:%i \n",Carbon);
printf ("Nitrogen:%i \n",Nitrogen);
printf ("Sulfur:%i \n",Sulfur);
printf ("Hydrogen:%i \n\n",Hydrogen);

//calculate molecular weight
molecularw= (Oxygen*O)+(Carbon*C)+(Nitrogen*N)+(Sulfur*S)+(Hydrogen*H);
printf("Molecular weight of glycine: %.3f \n", molecularw);


}

2. Write a program to compute and print the molecular weights of glutamic and glutamine.

#include <stdio.h>
#include <math.h>
#define O 15.9994
#define C 12.011
#define N 14.00674
#define S 32.066
#define H 1.00794
int main(void){
float molecularw,molecularw2;
int Oxygen,Nitrogen,Carbon,Sulfur,Hydrogen,Oxygen2,Carbon2,Nitrogen2,Sulfur2,Hydrogen2;

scanf("%i %i %i %i %i", &Oxygen, &Carbon, &Nitrogen, &Sulfur, &Hydrogen);
// input the numer of atoms
printf ("1.)Enter number of atoms:\n");
printf ("Oxygen:%i \n",Oxygen);
printf ("Carbon:%i \n",Carbon);
printf ("Nitrogen:%i \n",Nitrogen);
printf ("Sulfur:%i \n",Sulfur);
printf ("Hydrogen:%i \n\n",Hydrogen);

scanf("%i %i %i %i %i", &Oxygen2, &Carbon2, &Nitrogen2, &Sulfur2, &Hydrogen2);
// input the numer of atoms
printf ("2.)Enter number of atoms:\n");
printf ("Oxygen:%i \n",Oxygen2);
printf ("Carbon:%i \n",Carbon2);
printf ("Nitrogen:%i \n",Nitrogen2);
printf ("Sulfur:%i \n",Sulfur2);
printf ("Hydrogen:%i \n\n",Hydrogen2);

//calculate molecular weight
molecularw= (Oxygen*O)+(Carbon*C)+(Nitrogen*N)+(Sulfur*S)+(Hydrogen*H);
molecularw2= (Oxygen2*O)+(Carbon2*C)+(Nitrogen2*N)+(Sulfur2*S)+(Hydrogen2*H);
printf("Molecular weight for glutamic: %.2f \n", molecularw);
printf("Molecular weight for glutamine: %.2f \n", molecularw2);


}

3. Write a program that asks the user to enter the number of atoms of each of the five elements for an amino acid. Then compute and print the molecular weight for this amino acid.

#include <stdio.h>
#include <math.h>
#define O 15.9994
#define C 12.011
#define N 14.00674
#define S 32.066
#define H 1.00794
int main(void){
float molecularw;
int Oxygen,Nitrogen,Carbon,Sulfur,Hydrogen;
scanf("%i %i %i %i %i", &Oxygen, &Carbon, &Nitrogen, &Sulfur, &Hydrogen);

// input the numer of atoms
printf ("Enter number of atoms:\n");
printf ("Oxygen:%i \n",Oxygen);
printf ("Carbon:%i \n",Carbon);
printf ("Nitrogen:%i \n",Nitrogen);
printf ("Sulfur:%i \n",Sulfur);
printf ("Hydrogen:%i \n\n",Hydrogen);

//calculate molecular weight
molecularw= (Oxygen*O)+(Carbon*C)+(Nitrogen*N)+(Sulfur*S)+(Hydrogen*H);

printf("Molecular weight for this amino acid: %.3f \n", molecularw);

}
4. Write a program that asks the user to enter the number of atoms of each of the five elements for an amino acid. Then compute and print the average weight of the atoms in the amino acid.

#include <stdio.h>
#include <math.h>
#define O 15.9994
#define C 12.011
#define N 14.00674
#define S 32.066
#define H 1.00794
int main(void){
float molecularw,avgweight;
int Oxygen,Nitrogen,Carbon,Sulfur,Hydrogen;

scanf("%i %i %i %i %i", &Oxygen, &Carbon, &Nitrogen, &Sulfur, &Hydrogen);
// input the numer of atoms
printf ("Enter number of atoms:\n");
printf ("Oxygen:%i \n",Oxygen);
printf ("Carbon:%i \n",Carbon);
printf ("Nitrogen:%i \n",Nitrogen);
printf ("Sulfur:%i \n",Sulfur);
printf ("Hydrogen:%i \n\n",Hydrogen);

//average weigth 
avgweight= (Oxygen*O)+(Carbon*C)+(Nitrogen*N)+(Sulfur*S)+(Hydrogen*H)/(O+C+N+S+H);

//calculate molecular weight 
molecularw= (Oxygen*O)+(Carbon*C)+(Nitrogen*N)+(Sulfur*S)+(Hydrogen*H);
printf("The total weight of Amio acid: %.2f \n", molecularw);
printf ("The average weight of the Amino acid:%.2f\n",avgweight);
}