Posts

Showing posts from 2018

Sample Finals

Sample 1: // Point.h: #ifndef POINT_H #define POINT_H class Point { private:     double xcoord, ycoord; public:     Point();     Point(double x, double y);     bool operator==(const Point& p);     double operator-(const Point& b); }; #endif // POINT_H Point.cpp: #ifndef POINT_H #define POINT_H class Point { private:     double xcoord, ycoord; public:     Point();     Point(double x, double y);     bool operator==(const Point& p);     double operator-(const Point& b); }; #endif // POINT_H main.cpp: #include <iostream> //Required for cout #include "Point.h" using namespace std; int main() { //Declare and initialize objects. Point p1; Point p2(1.5, -4.7); //Test operators if( p1 == p2) { cout << "p1 is equal to p2" << endl; } else { cout << "Distance between p1 and p2 is " << p1 - p2 << endl; } return 0; } Sample 2: //Decoding mes...

Lab 25/ HW 25

Lab 25 (Ultrasonic): int trigPin = 13; //Sensor Trig pin connected to Arduino pin 13 int echoPin = 11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to target and return float targetDistance; //Distance to Target in inches float speedOfSound = 776.5; //Speed of sound in miles per hour when temp is 77 degrees. void setup() {   // put your setup code here, to run once:   Serial.begin(9600);   pinMode(trigPin, OUTPUT);   pinMode(echoPin, INPUT); } void loop() {   // put your main code here, to run repeatedly:   digitalWrite(trigPin, LOW); //Set trigger pin low   delayMicroseconds(2000); //Let signal settle   digitalWrite(trigPin, HIGH); //Set trigPin high   delayMicroseconds(15); //Delay in high state   digitalWrite(trigPin, LOW); //ping has now been sent   delayMicroseconds(10); //Delay in low state     pingTime = pulseIn(echoPin, HIGH); //pingTime...

Lab 24/ HW 24

Lab 24 (MPU): #include <iostream> #include <cmath> #include <fstream> #define FILENAME "fingerprints.txt" using namespace std; int main(void) { //Declare and initialize variables. int k = 0, min_num = 0; float min_dist = 100.0; string hand[5] = {"Thumb", "Index Finger", "Middle Finger", "Ring Finger", "Pinky Finger"}; double unknown[5], known[5]; cout << "Enter distance of thumb" << endl; cin >> unknown[0]; cout << "Enter distance of index finger" << endl; cin >> unknown[1]; cout << "Enter distance of middle finger" << endl; cin >> unknown[2]; cout << "Enter distance of ring finger" << endl; cin >> unknown[3]; cout << "Enter distance of pinky finger" << endl; cin >> unknown[4]; ifstream prints; prints.open(FILENAME); if (prints.fail()) {     cout << "Error o...

Lab 23/ HW 23

Lab/HW 23 (C++ Fingerprint): #include <iostream> #include <cmath> #include <fstream> #define FILENAME "fingerprints.txt" using namespace std; int main(void) { //Declare and initialize variables. int k = 0, min_num = 0; float min_dist = 100.0; string hand[5] = {"Thumb", "Index Finger", "Middle Finger", "Ring Finger", "Pinky Finger"}; double unknown[5], known[5]; cout << "Enter distance of thumb" << endl; cin >> unknown[0]; cout << "Enter distance of index finger" << endl; cin >> unknown[1]; cout << "Enter distance of middle finger" << endl; cin >> unknown[2]; cout << "Enter distance of ring finger" << endl; cin >> unknown[3]; cout << "Enter distance of pinky finger" << endl; cin >> unknown[4]; ifstream prints; prints.open(FILENAME); if (prints.fail()) {     cout <<...

Lab 22/ HW 22

Lab 22 (I2C Sensor): #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevi...

Lab 21/ HW 21

Lab 21 (BPM180): // This is the top of the program #include <Wire.h> #include "BMP180Lib.c" #include <SD.h> #define BMP180_ADDRESS 0x77 // I2C address of BMP180 // Read 1 byte from the BMP180 at 'address' char bmp180Read(unsigned char address) {  unsigned char data;  Wire.beginTransmission(BMP180_ADDRESS);  Wire.write(address);  Wire.endTransmission();  Wire.requestFrom(BMP180_ADDRESS, 1);  while(!Wire.available())  ;  return Wire.read(); } // Read 2 bytes from the BMP180 // First byte will be from 'address' // Second byte will be from 'address'+1 int bmp180ReadInt(unsigned char address) {  unsigned char msb, lsb;  Wire.beginTransmission(BMP180_ADDRESS);  Wire.write(address);  Wire.endTransmission();  Wire.requestFrom(BMP180_ADDRESS, 2);  while(Wire.available()<2)  ;  msb = Wire.read();  lsb = Wire.read();  return (int) msb<<8 | lsb; } short temperature; long pressure; // Use...