Posts

Showing posts from October, 2017

Day 15? Oct 17

For lab we had to control a motor using a potentiometer,we also included a switch. Here's our code //Simple Motor Speed Control Program const int MOTOR=9; const int POT=0; int min_val=0; int max_val=1023; int val=0;//Motor on Digital Pin 9 void setup() {  pinMode (MOTOR, OUTPUT); } void loop() { val=analogRead(POT);    val=map(val,min_val,max_val,0,255);   analogWrite(MOTOR,val); } Here's a link to the thing working We didn't have homework today

Day 13 Oct 10

Image
For homework we had to write a program that printed the peaks and valleys in feet here the code /* */ /* 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]; int total=0; int distance=0; 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=0; i<=nrows-1; i++) for (j=0; j<=ncols-1; j++) fscanf(grid,"%lf",&elevation[i][j]); /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); int count=0; for (i=1; i<=nrows-2; i++) for (j=1; j<=ncols-2; j++) { if ((elevation[i-1][j]<elevation[i][j]) && (elevatio...

Day 12 Oct 5

Image
For homework we had to generate a table based on user input here's the code //This program prints the altitude and velocity for a ballon over a given amount of time given in hours. #include <stdio.h> #include<math.h> #define FILENAME "balloon1.txt" int main(void){ double t; //t is in hours double alt_max,sum,start_time,end_time,alt,v, period; double time_incr,new_incr; alt_max=0; FILE *balloon; balloon=fopen(FILENAME,"w"); printf("Enter the start time,and end time, in hours:\n Values must be BELOW 48 hours \n"); scanf("%lf %lf",&start_time,&end_time); if(start_time > end_time) { printf("Please choose an end time larger than the start time."); exit(); } if(start_time<0 || end_time>48) { printf("Please enter values that are between 0 and 48"); exit(); } printf("Enter the time increment in minutes: \n must be BELOW 48 hours \n"); scanf("%lf",...

Day 10

Image
For day 10 we had to make a encrypting and decrypting program and also a program that generated random float values. I couldn't get this code to work, it would just print zeros. Here's the encrypt/decrypt code. I included both the encrypt and decrypt functions Here's the code for the random number that I couldn't get to work.

Day 9

Image
For today we had to create a program that lit up certain LEDs based on the distance measured by the PIR sensor Here's the code #include <Servo.h> const int SERVO =9; const int IR =0; const int LED1 = 3; const int LED2 = 5; const int LED3 =6; const int LED4= 11; Servo myServo; int dist1 =0; int dist2=0; int dist3=0; int dist4=0; void setup() {   myServo.attach(SERVO);   pinMode(LED1, OUTPUT);   pinMode(LED2, OUTPUT);   pinMode(LED3, OUTPUT);   pinMode(LED4, OUTPUT);   } int readDistance(int pos) {     myServo.write(pos);     delay(600);     int dist= analogRead(IR);     dist= map(dist,50,500,0,255);     dist =constrain(dist,0,255);     return dist; } void loop() {  dist1 = readDistance(15);   analogWrite(LED1,dist1);   delay(300);   dist2=readDistance(65);   analogWrite(LED2,dist2);   delay(300);   dist3=readDi...

Day 8

Image
For lab we had to connect the PIR sensor and the servo together to show that when the PIR sensor was triggered the servo would move. Here's the code #include <Servo.h> const int SERVO =9; const int IR =0; const int LED1 = 3; const int LED2 = 5; const int LED3 =6; const int LED4= 11; Servo myServo; int dist1 =0; int dist2=0; int dist3=0; int dist4=0; void setup() {   myServo.attach(SERVO);   pinMode(LED1, OUTPUT);   pinMode(LED2, OUTPUT);   pinMode(LED3, OUTPUT);   pinMode(LED4, OUTPUT);   } int readDistance(int pos) {     myServo.write(pos);     delay(600);     int dist= analogRead(IR);     dist= map(dist,50,500,0,255);     dist =constrain(dist,0,255);     return dist; } void loop() {  dist1 = readDistance(15);   analogWrite(LED1,dist1);   delay(300);   dist2=readDistance(65);   analogWrite(LED2,dist2);   delay(300);...

Day 7

Image
For lab we had to connect a speaker to the arduino, and modify the code to play a song. Here's my code for that. //Specify digital pin on the Arduino that the positive lead of the speaker is int speakerPin = 9; const int POT=0; int val = 0; void setup() {    Serial.begin(9600); //Start Serial Communication } //close setup void loop() {  /*Tone needs 2 arguments, but can take three  1) Pin#  2) Frequency - this is in hertz (cycles per second) which determines the pitch of the noise made  3) Duration - how long the tone plays  */   val = analogRead(POT);   if (val<=139)   {  tone(speakerPin, 1000, 500);  delay(1000); } if (val<=147 && val>=139)   {    tone(speakerPin, 150,500);  delay(1000);   }   if (val>=147&&val<=153) {    tone(speakerPin,400,500);  delay(1000); } if (val>=154) {    tone(speakerP...

Day 14

Image
For the homework,we had to create a program that finds the peaks and valleys from a data file called elevation.  I got everything working, except the count of the peaks. My count was all over the place. Here's a copy  of my code. /* */ /* 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]; int total=0; int distance=0; 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=0; i<=nrows-1; i++) for (j=0; j<=ncols-1; j++) fscanf(grid,"%lf",&elevation[i][j]); /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); int count...