-
Notifications
You must be signed in to change notification settings - Fork 1
/
allStructs.ino
60 lines (51 loc) · 2.06 KB
/
allStructs.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <Wire.h>
#include "SparkFunMPL3115A2.h"
#include <Adafruit_GPS.h>
#include <stdio.h>
MPL3115A2 myPressure;
SoftwareSerial mySerial(3, 2);
Adafruit_GPS myGPS(&mySerial);
typedef struct { //initialize structure
float altitude;
float velocity; // velocity to be implemented later (a_1 - a_0) / time_inbetween_readings
float latitude;
float longitude;
} state;
void setup() {
Wire.begin(); // Join i2c bus
Serial.begin(9600); // Start serial for output
myPressure.begin(); // Get sensor online
myGPS.begin(9600); // Get sensor online
//Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
//myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa
myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
typedef struct { //initialize structure
float altitude;
float velocity; // velocity to be implemented later (a_1 - a_0) / time_inbetween_readings
float latitude;
float longitude;
} state;
state init_state = {myPressure.readAltitude(), 20.0}; // random velocity picked
state init_state = {myGPS.latitude, myGPS.longitude}; // random velocity picked
// function prototype
void update_state(state *); // pointer to struct
}
void loop() {
state init_state;
update_state(&init_state); // function call pass memory address of init_state
Serial.print("Altitude(m):");
Serial.print(init_state.altitude, 2);
Serial.println();
Serial.print("Latitude(Degrees):");
Serial.print(init_state.latitude, 2);
Serial.print("Longitude(Degrees):");
Serial.print(init_state.longitude, 2); //2?
Serial.println();
}
void update_state(state *state_ptr){ // point to memory address (get contents of mem address)
state_ptr->altitude = myPressure.readAltitude(); // the altitude field in the struct that state_ptr points to is updated to current Altitude
state_ptr->latitude = myGPS.latitude;
state_ptr->longitude = myGPS.longitude;
}