/*************************************************************
This is an examples for the OD01 0.96 inch OLED Display
You can buy one on our store!
-----> [Link]
This example display a temperature and pressure captured
from the SW01 ☒CHIP text on the OLED display.
The display communicates over the I2C Bus.
*************************************************************/
#include <xSW01.h>
#include <xCore.h>
#include <xOD01.h>
#include <xSI01.h>
const int DELAY_TIME = 1500;
xSI01 SI01;
xSW01 SW01;
xOD01 OD01;
void setup() {
#ifdef ESP8266
[Link](2, 14);
#endif
[Link]();
// Starts the I2C communication
float mX, mY, mZ;
float mx_min, my_min, mz_min;
float mx_max, my_max, mz_max;
float mx_offset, my_offset, mz_offset;
float mx_calibrated, my_calibrated, mz_calibrated;
float mx_scale, my_scale, mz_scale;
static unsigned long startTime;
float avg_scale;
// Start the OLED Display OD01
[Link]();
// Start the SW01 Sensor
[Link]();
//Start the SI01 Sensor
[Link]();
// Display Example Name on OD01
[Link]("Hello World");
// send command to clear the display
[Link]();
//Using Gyroscope to determine direction
mx_max=0;my_max=0;mz_max=0;
mx_min=0;my_min=0;mz_min=0;
startTime=millis();
if (mX > mx_max) mx_max = mX;if (mY > my_max) my_max = mY;if (mZ > mz_max)
mz_max = mZ;
if (mX < mx_min) mx_min = mX;if (mY < my_min) my_min = mY;if (mZ < mz_min)
mz_min = mZ;
mx_offset = (mx_min + mx_max)/2;
my_offset = (my_min + my_max)/2;
mz_offset = (mz_min + mz_max)/2;
mx_scale = (mx_max - mx_min)/2;
my_scale = (my_max - my_min)/2;
mz_scale = (mz_max - mz_min)/2;
avg_scale=(mx_scale + my_scale + mz_scale)/3;
delay(DELAY_TIME);
}
void loop() {
// Create a variable to store the data read from SW01
float temperature, pressure, humidity, altitude;
float QNE;
float mX, mY, mZ;
float mx_min, my_min, mz_min;
float mx_max, my_max, mz_max;
float mx_offset, my_offset, mz_offset;
float mx_calibrated, my_calibrated, mz_calibrated;
float mx_scale, my_scale, mz_scale;
float avg_scale;
temperature = pressure = humidity = altitude = 0;
QNE = 0;
// request the sensor to read data
[Link]();
[Link]();
mX = [Link]();
mY = [Link]();
mZ = [Link]();
// Request SW01 to get the temperature measurement
// Temperature request is degrees celcius
temperature = [Link]();
// Display the temperature on the OLED display OD01
[Link]("-----");
[Link]("Temperature: ");
[Link](temperature);
[Link](" C");
// Request SW01 to get the pressure measurement
// Pressure request is in pascals
// This is the converter to kilo pascals
pressure = [Link]();
// Display the pressure on the OLED display OD01
[Link]("Pressure: ");
// Display a convertered kPa value
[Link](pressure/1000);
[Link](" kPa");
humidity = [Link]();
// Display the recoreded data over the Serial Monitor
[Link]("Humidity: ");
[Link](humidity);
[Link](" %");
// delay between sensor reads
QNE = [Link]();
altitude = [Link](101325);
[Link]("Altitude: ");
[Link](altitude);
[Link](" m");
[Link]("-----");
delay(DELAY_TIME);
// send command to clear the display
mX=[Link]();mY=[Link]();mZ=[Link]();
mx_calibrated = avg_scale/(mX - mx_offset);
my_calibrated = avg_scale/(mY - my_offset);
mz_calibrated = avg_scale/(mZ - mz_offset);
[Link](" MX: ");
[Link](mx_calibrated);
[Link](" MY: ");
[Link](my_calibrated);
[Link](" MZ: ");
[Link](mz_calibrated);
[Link]();
OD01.set2X();
[Link]("Magnetic: ");
[Link](" MX: ");
[Link](mx_calibrated);
[Link](" MY: ");
[Link](my_calibrated);
[Link](" MZ: ");
[Link](mz_calibrated);
[Link]();