Posts

Showing posts from October, 2017

DAY 16 HW

Image
/* */ /* This program reads a seismic data file and then */ /* determines the times of possible seismic events. */ #include <stdio.h> #define FILENAME "seismic1.txt" #define MAX_SIZE 1000 //#define THRESHOLD 1.5 int main(void) { /* Declare variables and function prototypes. */ int k,i, npts, short_window, long_window,thrsh,THRESHOLD; double sensor[MAX_SIZE], time_incr, short_power, long_power, ratio; FILE *file_ptr; double power_w(double *ptr,int n); /* Read sensor data file. */ file_ptr = fopen(FILENAME,"r"); if (file_ptr == NULL) { printf("Error opening input file. \n"); } else { fscanf(file_ptr,"%d %lf",&npts,&time_incr); if (npts > MAX_SIZE) { printf("Data file too large for array. \n"); } else { printf("Enter threshold value:"); scanf("%d",&THRESHOLD); if(THRESHOLD>1.00) { /* Read data into an array. */ for (k=0; k<=npts-1; k++) fscanf(file_ptr,...

day_14

Image
I'm not too sure on what the homework consists of. Since finding the values of each variable was the only thing that was asked us to do.I'm pretty sure that this is all that was wanted from us. #include<stdio.h> int main(void) { int i1,i2; int*p1, *p2; i1=5; p1=&i1; i2=*p1/2+10; p2=p1; printf("i1 value:%d adress:%u\n",i1,&i1); printf("i2 value:%d adress:%u\n",i2,&i2); printf("p1 value:%d\n",p1); printf("p2 value:%d\n",p2); return 0; } Lab: I had trouble getting the motor to work initially. It would vibrate when I plugged the battery in. After spending about an hour testing the comp i figured out that my battery was at 6.3V. Using a new battery worked. //Simple Motor Speed Control Program const int MOTOR=9;//Motor on Digital Pin 9 int pot=A0; int val=0; void setup() {  pinMode (MOTOR, OUTPUT);  Serial.begin(9600); } void loop() { val=analogRead(p...

Day_15

Image
programming homework: Initially I had trouble getting the code to even run, the pointers were confusing to understand for me because you know pointers.... David helped me out the next day before class and we figured out that i had a missing bracket and the code ran fine for the first modification. /* This program reads a data file of ENSO index values and */ /* determines the maximum El Nino condition in the file. */ #include <stdio.h> #define FILENAME "ENSO1.txt" #define MAX_SIZE 1000 int main(void) { /* Declare variables and function prototypes. */ int k=0, year[MAX_SIZE], qtr[MAX_SIZE], max_k=0,min_k=0,max_k_2,min_k_2; double index[MAX_SIZE]; for(int i =0;i<MAX_SIZE;i++) { year[i]=0; qtr[i]=0; index[i]=0; } FILE *enso; /* Read sensor data file. */ enso = fopen(FILENAME,"r"); if (enso == NULL) printf("Error opening input file. \n"); else { while (fscanf(enso,"%d %d %lf",year+k,qtr+k,index+k)>=3) { if(*(i...

Day_12

Image
This lab was pretty straight forward, the only problem I had was that the sensor value was reading a range from a few hundred to seven thousand, I'm not sure why. // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(8,9,4,5,6,7); int potPin1 = A1; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.clear(); pinMode(potPin1, INPUT); } void loop() { lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0 lcd.print("SensorVal: "); // Prints Sensor Val: to LCD lcd.print(analogRead(potPin1)); // Prints value on Potpin1 to LCD }

Day_13

Image
Comment: I had a lot of trouble understanding how to code works for the homework, I couldn't finish all of the modifications without getting an error. So I only finished the first three modifications, which took me a long time to develop. For this lab I initially had trouble getting the speaker to change the pitch according the the change in temperature. Turns out I had an extra if statement in my program and that resolved the problem. I spent about 4 hours debugging before I found the extra if statement. Also, I used a potomieter because the speaker would make the lcd screen go crazy since without the pot there was no resistance. /* This program determines the locations of peaks in an */ /* grid of elevation data. */ #include <stdio.h> #define N 25 #define FILENAME "grid1.txt" int main(void) { /* Declare variables. */ int nrows, ncols, i, j,count=0,count_2=0; double elevation[N][N]; double valleys[N][N]; FILE *grid; /* Read information from a data fi...