Posts

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);   }}}
project 1 song prepare song 1 Mario overworld theme #define NOTE_B2  123  #define NOTE_C3  131  #define NOTE_CS3 139  #define NOTE_D3  147  #define NOTE_DS3 156  #define NOTE_E3  165  #define NOTE_F3  175  #define NOTE_FS3 185  #define NOTE_G3  196  #define NOTE_GS3 208  #define NOTE_A3  220  #define NOTE_AS3 233  #define NOTE_B3  247  #define NOTE_C4  262  #define NOTE_CS4 277  #define NOTE_D4  294  #define NOTE_DS4 311  #define NOTE_E4  330  #define NOTE_F4  349  #define NOTE_FS4 370  #define NOTE_G4  392  #define NOTE_GS4 415  #define NOTE_A4  440  #define NOTE_AS4 466  #define NOTE_B4  494  #define NOTE_C5  523  #define NOTE_CS5 554  #define NOTE_D5  587  #define NOTE_DS5 622  #define NOTE_E5  659  #define NOT...
lab motor 9/20/2018 #include <Servo.h> const int SERVO=9; const int PIR=2;//The PIR is connected to pin 2 Servo myServo; void setup() {  myServo.attach(SERVO); } void loop() {   if ( digitalRead(PIR)==LOW)   {myServo.attach(180);   delay(15);}   else {  myServo.attach(0);  delay(15); }}