Posts

Showing posts from September, 2017

Day_8

Image
1)the servo homework was pretty straight forward , so completing it wasn’t too much of a challenge. The biggest problem for me was not initially assigning the servo position, so it never returned back to the original position. And I also did a for loop telling it to return to initial position once the servo reached it’s specified angle.Thankfully Mathew was able to help me figure out why my servo was acting weird. I also wanted to add a buzzer when the motion read HIGH but I didn’t had time. WORKING CODE: #include <Servo.h> const int SERVO=9; //Servo on Pin 9 const int PIR = 2; //PIR in Pin 2 Servo myServo; const int Servo_Position_1 = 90; void setup() {  myServo.attach(SERVO);  pinMode (PIR, INPUT);  Serial.begin(9600); } void loop() {   if (digitalRead(PIR) == HIGH)   {     Serial.println("MOTION DETECTED");           myServo.write(180);     delay(15);     } ...

Fritzing lab

Image

Day 7 HW

Image
1) Two Dice Role At first I managed to program a dice to generate random numbers between 1-6. So  i just repeated that for the second dice. The problem now is to allow input from the user to allow how many times they wanted to role the dice. Instead of using a "for" loop and creating a new variable and setting it less then and equal to the desired user input, I used a while statement. Basically telling the program to increment the numbers of roles by one until it is equal to the number of the user input. My program ran infinitely, not knowing at the time I told the program while the number of roles is equal to user input, keep incrementing the number of roles. But since the number of roles always equal the number of the input it keeps looping infinitely. I tried debugging for an hour before rage quitting for another two hours. After I went on google and went on different forums  then figured out that I have to set the number of roles < user input because in a while loop i...

Day_5

Image
comment: I couldn't figure out the modifications for the homework, since I would always get 0 for my results for all of my modification. It's probably my loop and if statement making the code spit out 0. I'm not too sure on how to fix the problem, since I barely understand loops and I find it tricky working with the if statements. On the brighter side, I managed to get the RGB to display the color I want from blue, and red. So that's somewhat of a win. The arduino lab wasn't too difficult, unlike debounce which, stills haunts me. #include <stdio.h> #include <math.h> #define PI 3.141592 int main (void) { double per_1, per_2, wh_2, wl_1, wl_2, wl_sum, wave_1, wave_2, wavemax, wave_sum, time; int wh_1, wavelowest,n_input, phase_1;  printf("Input period and wave height:\n" );   printf("Wave 1: \n");   scanf(" %f %f", &per_1, &wh_1);   printf("Wave 2: \n");   scanf(" %f %f", &per_2, ...

Day_4

Comments: The programming homework was pretty straight forward, well at least I think it is anyway. What's killer was the arduino homework, since I have to implement the debounce, which I have yet to figure out. I managed to change the color of the RGB to the desired color, but haven't managed to get the color to change on the button pushes. I will probably ask David to help me figure out how to debounce the button to get the RGB to work. 2. Give the value of a after the following set of statements is executed. int a = 750; ... if (a>0) (which it is)  if (a >= 1000) (It's not) a = 0; else if (a < 500) a *= 2;(It's not)  else a *= 10; [a*10 =a], since a =750, [a=750*10] else a += 3; (not true) answer 7,500 1) const int BLED=9; //Blue LED on Pin 9 const int GLED=10; //Green LED on Pin 10 const int RLED=11; //Red LED on Pin 11 const int BUTTON=2; //The Button is connected to pin 2 boolean lastButton = LOW; //Last Button State boolean currentButton...

log code

1) /*  log problem   */ #include <stdio.h> #include <math.h> int main (void) {   /*  declare variable  */   double positive_integers, result;   printf("Enter positive_integers: \n");   scanf("%lf", &positive_integers);   /*  calculations to find result of base2  */   result = log(positive_integers)/log(2);   printf("THe result of logarithm of base 2 for %5.5f is %5.5f\n",positive_integers,result);   return 0; } 2) /*  log problem   */ #include <stdio.h> #include <math.h> int main (void) {   /*  declare variable  */   double positive_integers, result;   printf("Enter positive_integers: \n");   scanf("%lf", &positive_integers);   /*  calculations to find result of base8  */   result = log(positive_integers)/log(8);   printf("THe result of logarithm of base 2 for %5.5f is %5.5f\n",positive_integers...

Velocity code

#include <math.h> #include <stdio.h> int main(void) {   /*  declare variables */   double Velocity,acceleration, t_s;   printf("Input time elapsed in seconds:\n");   scanf("%lf",&t_s);   /*  calculations to find Velocity*/   Velocity = .00001*(t_s*t_s*t_s)-.00488*(t_s*t_s)+.75795*(t_s)+181.3566;   acceleration = 3-.000062*(Velocity*Velocity);   printf("Velocity:%lf m/s\n", Velocity);   printf("Acceleration: %lf m/s^2 \n",acceleration);  return 0; } problem 1) gcc version 4.6.3   Input time elapsed in seconds:  56 Velocity:210.254280 m/s Acceleration: 0.259175 m/s/s problem 2)   gcc version 4.6.3   Input time elapsed in seconds:  25 Velocity:197.411600 m/s Acceleration: 0.583777 m/s^2 problem3) #include <math.h> #include <stdio.h> int main(void) {   /*  declare variables */   double Velocity,acceleration, t_s,t_m;   ...

salinty code problem 2-4

/*  salinity problem 2  */ #include <stdio.h> #include <math.h> int main(void) {   /*  declare variables */   double a,b,c, f_a,f_b,f_c,t_c; printf("Enter first salinity and freezing temperature in Farehient: \n"); scanf("%lf %lf",&a,&f_a); printf("enter second salinity and freezing temperature in farehient: \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); t_c = (f_b -32)*.555555; printf("new freezing termperature in degrees F: %lf \n", t_c); return 0; } problem 3)  No, if the user inputs the data in Centigrade, then there wouldn't need to be any change. if the user input the values in Fahrenheit then there would have to be a change in code to convert Fahrenheit to Centigrade problem 4) /*  salinity problem   */...

HW_3

Image
Comment: The coding is starting to get more difficult at this point, I went to different forums and watched you tube videos on how to trouble shoot, because I forgot a parenthesis. I didn't understand interpolation initially, and had to watch a you tube video on it. I probably wouldn't have got the code to work if Mr.Mason din't give us a sample code, god bless! The arduino debounce I never got it to work properly, everytime I pushed the button it wouldn't cycle properly. So, I'm assuming that I didn't get the code to work properly, or maybe it's a mechanical problem. #include <stdio.h> #include <math.h> int main(void) {   /*  declare variables */   double a,b,c, f_a,f_b,f_c; printf("Enter first salinity and freezing temperature: \n"); scanf("%lf %lf",&a,&f_a); printf("enter second salinity and freezing temperature in farehient: \n"); scanf("%lf %lf",&c, &f_c); printf("enter...

HW_2

Image
Comments: So, for this program I never had too much trouble since,  we basically did the same coding process on homework 1.  This time, the questions just more specific on what the accuracy if the final  answer should be. I especially enjoyed the atomic weight code since. I'm not too sure why but I found it to be enjoyable. Asking for the user input and printing the results were pretty cool. //  main code without any modfication   // #include <stdio.h> #include <math.h> int main(void) {   /* declare variables  */   double femur, femur_m, femur_f, humerus, humerus_m, humerus_f;   /*  Input from user */   printf("enter length of femur: \n");   scanf("%lf", &femur);   printf("enter length of humerus: \n");   scanf("%lf", &humerus);   /* computing height based on humerus and femur  */   femur_f = femur*1.94 + 28.7;   femur_m = femur*1.88 + 32;   humerus_f = hum...

HW_2_Arduino

int LED1 = 13; int LED2 = 12; int LED3 = 11; int LED4 = 10; int LED5 = 9; int LED6 = 8; void setup() {   // put your setup code here, to run once: pinMode ( LED1, OUTPUT); pinMode ( LED2, OUTPUT); pinMode ( LED3, OUTPUT); pinMode ( LED4, OUTPUT); pinMode ( LED5, OUTPUT); pinMode ( LED6, OUTPUT); } void loop() {   // put your main code here, to run repeatedly: digitalWrite(LED1, HIGH); // turn on LED1 delay(200);  //delay 2s digitalWrite (LED2, HIGH); // tunrs on LED2 delay(200);  //delay 2s digitalWrite (LED3, HIGH); // turns on LED3 delay(200); //delay 2s digitalWrite(LED4, HIGH); // turn on LED4 delay(200);  //delay 2s digitalWrite (LED5, HIGH); // tunrs on LED5 delay(200);  //delay 2s digitalWrite (LED6, HIGH); // turns on LED6 delay(200); //delay 2s digitalWrite(LED1, LOW); //turns off delay(200); digitalWrite(LED2, LOW); //turns off delay(200); digitalWrite(LED3,LOW); //turns off delay(200); digitalWrite(LED4, LOW); ...