Posts

Showing posts from October, 2017

Day 16

Lab: //potentiometer control int M1_Left = 12; //Motor Input 1 int M1_Right = 11; //Motor Input 2 int POT = 0; int spd = 0; void stop(){  digitalWrite(M1_Left, LOW);  digitalWrite(M1_Right , LOW); } void setup() {  pinMode(M1_Left, OUTPUT);  pinMode(M1_Right , OUTPUT);  Serial.begin(9600); } void loop() {  POT = analogRead(A1);  if(POT >= 562)  {  spd = map(POT, 562,1023,0,255);  analogWrite(M1_Left, spd);  digitalWrite(M1_Right, LOW);  }  else if(POT <= 462)  {  spd = map(POT, 462,0,0,255);  analogWrite(M1_Right, spd);  digitalWrite(M1_Left, LOW);  }  else if(POT>462 && POT < 562)  {   stop();  }  delay(10);  Serial.print(POT);  Serial.print("    ");  Serial.println(spd); } Homework: //Serial motor control int M1_Left = 12; //Motor Input ...

Day 15

Image
LAB: //Simple Motor Speed Control Program with potentiometer const int MOTOR=9; //Motor on Digital Pin 9 const int POT=1; //Pot on A1 int val = 0; void setup() {  pinMode (MOTOR, OUTPUT);  Serial.begin(9600); } void loop() {   val = analogRead(POT);   Serial.println(val);   val = map(val, 0, 1026, 0, 256);   val = constrain(val, 0, 256);   analogWrite(MOTOR, val);   delay(10); } Homework: int il, i2; int *pl, *pls; ... il = 5; p1 = &il; i2 = *p1/2 + 10; p2 =  pl; What is the value of i1? - 5 What is the value of i2? - 12.5  What is the value of *p1? - 5  What is the value of *p2? - 5

terrain mapping valleys

/* ---------------------------------------------------- */ /* 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, peaks; double elevation[N][N]; FILE *grid; /* Read information from a data file. */ grid = fopen(FILENAME,"r"); if (grid == NULL) { printf("Error opening input file\n"); } else { fscanf(grid,"%d %d",&nrows,&ncols); for (i=1; i <= nrows - 1; i++) { //printf("1"); for (j=0; j <= ncols - 1; j++) { fscanf(grid,"%lf",&elevation[i][j]); } } //printf("1"); /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); for (i=2...

terrian mapping1

/* ---------------------------------------------------- */ /* 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; double elevation[N][N]; FILE *grid; /* Read information from a data file. */ grid = fopen(FILENAME,"r"); if (grid == NULL) { printf("Error opening input file\n"); } else { fscanf(grid,"%d %d",&nrows,&ncols); for (i=1; i <= nrows - 1; i++) { //printf("1"); for (j=0; j <= ncols - 1; j++) { fscanf(grid,"%lf",&elevation[i][j]); } } //printf("1"); /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); for (i=2; i ...

weather balloon with peak

Image
#include <stdio.h> #define FILENAME "balloon1.txt" float altitude, velocity, stime, etime, increments, n; int main(void){ //get variables printf("Enter start and end time in hours: \n"); scanf(" %f %f", &stime, &etime); printf("Enter increment in hours: \n"); scanf(" %f", &increments); FILE *balloon; /* Open output file. */ balloon = fopen(FILENAME,"w"); fprintf(balloon, "Time Altitude Velocity"); //printf("1"); if (stime > 48 || etime > 48) { printf( "Please enter a time less than 48 hours \n"); } //printf("2"); else if (increments <= 0) { printf("Please input an increment greater than 0"); } //printf("3"); else { float peak = 0, tpeak = 0; //find altitude and velocity for (n = stime; n ...

weather balloon

Image
#include <stdio.h> #define FILENAME "balloon.txt" float altitude, velocity, stime, etime, increments, n; int main(void){ //get variables printf("Enter start and end time in hours: \n"); scanf(" %f %f", &stime, &etime); printf("Enter increment in hours: \n"); scanf(" %f", &increments); FILE *balloon; /* Open output file. */ balloon = fopen(FILENAME,"w"); fprintf(balloon, "Time Altitude Velocity"); if (stime > 48 || etime > 48) { printf( "Please enter a time less than 48 hours \n"); } else { //find altitude and velocity for (n = stime; n <= etime; n + increments) { altitude = -0.12*(n*n*n*n) + 12*(n*n*n) - 380*(n*n) + 4100*(n) + 220; velocity = -0.48*(n*n*n) + 36*(n*n) - 760*n + 4100; fprintf(balloon, "\n %.2f hours %.2f m %.2f m/s \n", n, altitude, velocity); } } //close file fclose(balloon); return 0; } //For loop is not chan...