Posts

Showing posts from October, 2018
HW        10/8     need to fix  #include <stdio.h> #define NROWS 3 #define NCOLS 10 #define FILENAME "Mtsacballoon.txt" int main(void) { /* Declare variables. */ int i, j; int Mtsacballoon[NROWS][NCOLS], col_sum; FILE *file_in; file_in = fopen(FILENAME,"r"); if (file_in == NULL) printf("Error opening input file. \n"); else { for (i=0; i<=NROWS-1; i++) for (j=0; j<=NCOLS-1; j++) fscanf(file_in,"%d",&Mtsacballoon[i][j]); /* Compute and print daily averages. */ for (j=0; j<=NCOLS-1; j++) {time =1; for (i=0; i<=NROWS-1; i++) h=(-0.12*pow(time,4)+(12*pow(time,3))-(380*time*time)+(4100*time)+220); v= -0.48*pow(time,3)+(36*time*time)-(760*time)+4100; printf("time %d: height = %.2f: velocity= %.2f: \n", j+3, h, v/3600); } /* Close file. */ fclose(file_in); } /* Exit program. */ return 0; }
#include <stdio.h> #define NROWS 8 #define NCOLS 7 #define FILENAME "power1.txt" int main(void) { /* Declare variables. */ int i, j; int power[NROWS][NCOLS], col_sum; FILE *file_in; /* Read information from a data file. */ file_in = fopen(FILENAME,"r"); if (file_in == NULL) printf("Error opening input file. \n"); else { for (i=0; i<=NROWS-1; i++) for (j=0; j<=NCOLS-1; j++) fscanf(file_in,"%d",&power[i][j]); /* Compute and print daily averages. */ for (j=0; j<=NCOLS-1; j++) { col_sum = 0; for (i=0; i<=NROWS-1; i++) col_sum += power[i][j]; printf("Day %d: Average = %.2f \n",j+1,(double)col_sum/NROWS); } fclose(file_in); /* Close file. */ } return 0; /* Exit program. */ }
#include <Servo.h> const int SERVO =9; const int IR =0; //Ir distance Sensor on Analog pin 0 int int pin[]={5,6,7}; int k =0; Servo myServo; //servo objerct int dist =0; //Quadrant void setup () { myServo.attach(SERVO); } void loop() {   for(k=0; k<=100;k+=15)   dist = readDistance(k);   delay(10); } int readDistance (int pos) {   myServo.write(pos); //Move to given position   delay(600); // wait for servo to move   int dist = analogRead(IR); // read IR sensor   dist = map(dist, 50, 500, 0, 255); // scale to read led range   dist = constrain(dist, 0, 255);   return dist; // return scaled distance   }
HW   day 11       10/4/2018 1   Write a program that will print a table of the altitude and the velocity for this weather balloon using units of meters and meters per second. Let the user enter the start time, the increment in time between lines of the table, and the ending time, where all the time values must be less than 48 hours. Use the program to generate a table showing the weather balloon information every 10 minutes over a 2-hour period, starting 4 hours after the balloon was launched. #include<stdio.h> #include<math.h> int main(void) { // declare the variables double ini_time, inc_time, Ed_time, time, h, v; // for question 2 double max_h=0, max_time=0; do{ // read the input printf(" \nEnter the values of the table \n"); printf("\n Enter start time \n"); scanf("%lf",&ini_time); printf(" Enter incresement time \n"); scanf("%lf",&inc_time); printf(" Enter ending time \n...
Image
control servo by number #include <Servo.h> const int SERVO=7;  // servo on in 7 Servo myServo; int val; void setup() {  Serial.begin(9600);       //Serial Port at 9600 baud  //Set pins as outputs  myServo.attach(SERVO);   Serial.print("angle degree =  ");       // input angle val } void loop() {  //Keep working as long as data is in the buffer  while (Serial.available() > 0) {  val = Serial.parseInt();         // valid integer  if (Serial.read() == '\n')         //Done transmitting  Serial.print(val);   //print val   Serial.println("  degree   ");       // print unit degree     Serial.print("angle degree =  ");    // keep printing the next val  {  //set servo  myServo.write(val);   }}}