Lab 14/ HW 14

LAB/HW 14 (Inclinometer):

#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int xpin = A1;
int ypin = A2;
byte degreesign[8] = {                //Degree sign
 0b01100,
 0b10010,
 0b10010,
 0b01100,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 };
void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
}

void loop()
{
  int xval = analogRead(xpin);
  int yval = analogRead(ypin);

  int x = xval - 325;
  int y = yval - 325;

  float xg = map(xval, 260.00, 390.00, -1, 1);
  float yg = map(yval, 260.00, 390.00, -1, 1);

  float angle = (atan2(y,x)*180)/PI;

  lcd.createChar(0, degreesign);
  lcd.setCursor(0,0);
  lcd.print("Angle: ");
  lcd.print(angle);
  lcd.print(byte(0));
  lcd.setCursor(0,1);
  lcd.print("Gx:");
  lcd.print(xg*9.81);
  lcd.print(" Gy:");
  lcd.print(yg*9.81);
  Serial.print(angle);
  Serial.print("\t");
  Serial.print(xval);
  Serial.print("\t");
  Serial.println(yval);
  delay(100);
}


HW 14 (La Nina)

Enso data Reader:
/* This program reads a data file of ENSO index values and */
/* determines the maximum El Nino condition in the file. */
#include <stdio.h>
#include <math.h>
#define FILENAME "ENSO2.txt"
#define MAX_SIZE 1000
int main(void)
{

/* Declare variables and function prototypes. */
int k=0, year[MAX_SIZE], qtr[MAX_SIZE], min_k=0, zero_k=0;
double index[MAX_SIZE];
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)
{
printf("%d %d %.2lf\n", *(year+k), *(qtr+k), *(index+k));
if (*(index+k) < *(index+min_k))
min_k = k;
}
if (fabs(*(index+k)) < fabs(*(index+zero_k)))
{
zero_k = k;
k++;

/* Print data for maximum La Nina condition. */
printf("Maximum La Nina Conditions in Data File \n");
printf("Year: %d Month: %d Index: %.2lf Data Points: %d\n",
*(year+min_k),*(qtr+min_k),*(index+min_k), k);
printf("\nConditions closest to normal\n");
printf("Year: %d Month: %d Index: %.2lf\n",*(year+zero_k),*(qtr+zero_k),*(index+zero_k));
/* Close file. */
fclose(enso);
}
/* Exit program. */
return 0;
}

Comments

Popular posts from this blog

Lab 13/ HW 13

Lab 21/ HW 21