Posts

Day 19 HW

Comment: The program took me awhile to figure out how to correctly modify the header file so that the program would work. I never really understood how to get modification 3 and up to work. Also I never got the interrupt to work correctly on my arduino. Initially, I didn't write attach interrupt and spent a few hours wondering why I couldn't get the interrupt to work.  The furthest I got was to get the led to change colors when I pressed the button, but never got the cds value to change the led. #include <stdio.h> #define FILENAME "waves2.txt" /* Define structure to represent a tsunami. */ struct tsunami { int mo, da, yr, fatalities; double max_height; char location[20]; }; int main(void) { /* Declare variables. */ int k=0,i=0, npts,max_fata=0; double max=0, sum=0, ave; struct tsunami t[100]; FILE *waves; /* Read and print information from the file. */ waves = fopen(FILENAME,"r"); if (waves == NULL) printf("Error opening data...

Day_17

Image
Comment: Initially, Mathew and I had trouble figuring out which sides of the joysticks correspond to which analog values. We serial printed the raw data and moved the joystick around to figure out the axis. After we figured the axis we did some calibration to the joystick so that it works near perfect. // Arduino pin numbers const int SW_pin = 2; // digital pin connected to switch output const int X_pin = 0; // analog pin connected to X output const int Y_pin = 1; // analog pin connected to Y output int M1_Left = 12; //Motor Input 1 int M1_Right = 11; //Motor Input 2 int M2_Left = 10; //Motor Input 1 int M2_Right = 9; //Motor Input 2 void setup() {  pinMode(SW_pin, INPUT);  digitalWrite(SW_pin, HIGH);  Serial.begin(115200); } void loop() {  Serial.print("Switch: ");  Serial.print(digitalRead(SW_ pin));  Serial.print("\n");  Serial.print("X-axis: ");  Serial.print(analogRead(X_ pin));  Serial....

Day_11

Image
Comment: For this code I didn't finish the last modification,since I couldn't figure it out. David told me that my brackets were confusing and that it needed to be work on. This homework took me a while to figure out, since i wasn't too sure on what to name my header file at first. Display: the maximum altitude #include <stdio.h> #include <math.h> //Define the name of the file //#define FILENAME "balloon1.txt" int main(void) { //Declaring variable double initial_val,increment_val,final_val,time_val,velocity_val,height_val; FILE *balloon; //Read the input from the user balloon=fopen("balloon1.txt","w"); //User input with scan and printf printf("Enter the values for the table in hours\n"); printf("\nEnter the intial value for time \n"); scanf("%lf", &initial_val); printf("enter the increment value:\n"); scanf("%lf",&increment_val); printf("Enter the ...

Day_10

Image
Comment:  This homework took me a few hours to finish, I had David helped me with getting the code to work. He mentioned using the ASCii table and using that, we can increase the array by two because, every character has an hex or decimal integer associated with it. #include<stdio.h> #include<stdlib.h> #include<string.h> void encrypt(char arr[]) {  int i;  for(i=0;i<strlen(arr);i++)  {    char ch;      ch=arr[i];      if(ch == 'y')    {    ch = 97 ;    arr[i] = ch;    }    else if(ch == 'z' )      {     ch =98;     arr[i] = ch;    }    else    {    arr[i] = ch+2;    }  } } void decrypt(char arr[]) {  int i;  for(i=0;i<strlen(arr);i++)  {    char ch;   ch=arr[i];   if(ch=='a')   { ...

Day_9

Comment: We worked on the code in class and it worked well. It was interesting working with the distance sensor and integrating it with the servo and led.  */ //Sweeping Distance Sensor #include <Servo.h>  const int SERVO  =9;   //Servo on Pin 9  const int IR     =0;   //IR Distance Sensor on Analog Pin 0  const int LED1   =3;   //LED Output 1  const int LED2   =5;   //LED Output 2  const int LED3   =6;   //LED Output 3  const int LED4   =11;  //LED Output 4 Servo myServo;     //Servo Object int dist1 = 0;     //Quadrant 1 Distance int dist2 = 0;     //Quadrant 2 Distance int dist3 = 0;     //Quadrant 3 Distance int dist4 = 0;     //Quadrant 4 Distance void setup() {     myServo.attach(SERVO); //Attach the Servo   ...

Project 1

Image
Comment: At first Mathew and I didn't know what we wanted to do for the first project. After bouncing around a few ideas we settled on a a dj box that does shoots light/lasers depending on the CDS analog value. We cut holes in the cups then wedge the CDS sensor then attached the lasers and led to the arduino. What Mathew and I had the most trouble was the wiring since we had 4 CDS, 4 lasers, and 4 led. We also ran out of wires so we had to strip and solder a lot of wires together, which got really messy rally fast. The final project didn't work as intended, the connections of the wires were really bad, so some of the lights didn't work. //Project 4 Mason int BUTTON_1 = 4;// First button on pin 4 is a mute button for the music int BUTTON_2 = 3;// Second button on pin 3 controls Imperial March music int buttonState_1 = LOW;//This variable stores the on/off state of the mute button int buttonState_2 = LOW;//This variable stores the on/off state of the music button int ...

Day_6

Image
Comment: Originally, I couldn't figure how to get the modification for the user input to select the quadrant in which they want. I was more confused with understanding how longitude and latitude correlate with which reference from the user input. I still couldn't figure out why the code wouldn't compile, even with David's help. For the arduino homework I initially had trouble getting the PIR sensor to sens my hand. My code would cycle through between high and low, and it turns out that I didn't calibrate the PIR sensitivity to the lowest, and that fixed the problem once I did. /*  This program determines the distance between two points    */ /*  that are specified with latitude and longitude values      */ /*  that are in the Northern Hemisphere.                       */ #include <stdio.h> #include <math.h> #define PI 3.141593 int main(void) { /*  Declare variables a...