Day_6

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 and function prototype.  */
double lat1, long1, lat2, long2,s,lat1_s, long1_s, lat2_s, long2_s;
double gc_distance(double lat1,double long1,
double lat2,double long2);
/*  Get locations of two points.  */
if(scanf("%lf",&s));
{
  printf("Great Circle Distance: %.0f miles \n",
-gc_distance(lat1,long1,lat2,long2));
}
else
{
printf("Is it in the Northern or Southern Hemisphere\n");
scanf("%lf",&s);
printf("Enter latitude north and longitude west ");
printf("for location 1: \n");
scanf("%lf %lf",&lat1,&long1);
printf("Enter latitude north and longitude west ");
printf("for location 2: \n");
scanf("%lf %lf",&lat2,&long2);


/*  Print great circle distance.  */
printf("Great Circle Distance: %.0f miles \n",
gc_distance(lat1,long1,lat2,long2));

/* Print the angle between two vectors */
/*  Exit program.  */
return 0;
}

/*  This function computes the distance between two            */
/*  points using great circle distances.                       */
double gc_distance(double lat1,double long1,
double lat2,double long2)
{
/*  Declare variables.  */
double rho, phi, theta, gamma,gamma_2, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/*  Convert latitude,longitude to rectangular coordinates.  */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/*  Compute angle between vectors.  */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
gamma_2 = acos(dot/(dist1*dist2));
printf("The angles between the two vectors are: %f \n", gamma_2);

/*  Compute and return great circle distance.  */
return gamma*rho;

}




//var
int motion = 2;
int pit = 0;
int led = 9;
void setup()
{
  //setupcode
  //Pin modes
  pinMode(2,INPUT); //motion sensor connected to this pin
  pinMode(9,OUTPUT);  //LED is binded to pin 9
  pinMode(0,INPUT); //pit sensor binded
  Serial.begin(9600);
}
void loop()
{
  //main code
  motion = digitalRead(2);
  pit = digitalRead(0);
  if (motion == HIGH)
  {
    digitalWrite(9,HIGH); //LED IS ON WHEN MOTION
    Serial.println("MOTION DECTED");
    delay(50);
  }
 if(pit == HIGH && motion ==LOW);
    {
    digitalWrite(9,LOW);
    Serial.println("there is light but no motion");
    }
  if (pit ==LOW && motion ==LOW);
  {
    digitalWrite(9,HIGH);
    delay(200);
    digitalWrite(9,LOW); //LED IS OFFF WHEN NO MOTION
    Serial.println("NO MOTION DECTED1");
    delay(50);
  }
}







//var
int motion = 2;
int pit = A5;
int led = 9;
boolean PIR;
int val;

void setup()
{
  //setupcode
  //Pin modes
  pinMode(motion,INPUT); //motion sensor connected to this pin
  pinMode(led,OUTPUT);  //LED is binded to pin 9
  digitalWrite(led,LOW);
  pinMode(pit,INPUT); //pit sensor binded
  Serial.begin(9600);
}
void loop()
{
  //main code
  PIR = digitalRead(motion);
  val = analogRead(pit);
  Serial.print("Motion: ");
  Serial.println(PIR);
  if (PIR == HIGH)
  {
    digitalWrite(led,HIGH); //LED IS ON WHEN MOTION
    Serial.println("MOTION DECTED");
    delay(50);
  }
 else if( val>10  && PIR ==LOW);
    {
    digitalWrite(led,LOW);
    Serial.println("there is light but no motion");
    }
  if (val<3 && PIR ==LOW);
  {
    digitalWrite(9,HIGH);
    delay(200);
    digitalWrite(9,LOW); //LED IS OFFF WHEN NO MOTION
    Serial.println("NO MOTION DECTED1");
    delay(50);
  }
}


Comments

Popular posts from this blog

Day_13

Day 18 WH