Saturday, December 9, 2017

16 November 2017- Day 23- C++ Skills Improvement/BMP180 Pressure Sensor

Day 23: The lab for today included the BMP180 sensor.  This sensor is capable of reading pressure value range between 30,000 and 110,000 Pascals.  The board also include a temperature sensor that is capable of detecting a range between 0 and 65 C.  This sensor is ideal for measuring pressure changes and can be utilized for altimetry inside of our rocket project.  The board is I2C compatible which makes it a great addition to any related projects using this digital interface.


(A simple connection to the Arduino board for the BMP180)
 Note that this sensors maximum supply voltage is 3.6v.  Do not connect it to the 5v pin on the arduino.
For the lecture portion of class we were given more insight on a C++ program that can determine which direction the trade winds will be blowing.  This following is the program for the tradewinds:
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
/*  Declare variables.  */
int r, c, k, maxk=0;
int grid[5][5], category[8]={0,0,0,0,0,0,0,0};
double perc;
char* direction[8]={"N  ","NE ","E  ","SE ","S  ",
"SW ","W  ","NW "};
ifstream winds;
/*  Read and print information from the file.  */
winds.open("winds1.txt");
if (winds.fail())
     cout << "Error opening input file." << endl;
else
     {
     for (r=0; r<=4; r++)
          winds >> grid[r][0] >> grid[r][1] >> grid[r][2]
          >> grid[r][3] >> grid[r][4];
     //  Determine sums for the direction categories.
     for (r=0; r<=4; r++)
          for (c=0; c<=4; c++)
          {
          k = grid[r][c];
          category[k]++;
          }
//  Determine category with maximum sum.
     for (k=0; k<=7; k++)
          if (category[k] > category[maxk])
               maxk = k;
//  Print report.
cout.setf(ios::fixed);
cout.precision(1);
perc = (double)category[maxk]/25*100;
cout << "The wind is blowing from the " << direction[maxk–1]
<< perc << "% of the time." << endl;
//  Close file.
winds.close();
}
//  Exit program.
return 0;

}

For homework, we took this program and modified it to output a percentage and direction of the winds blowing, a possible hurricane/cyclone output, and also read from a data file of 100 rows by a 100 columns.  

No comments:

Post a Comment