#include <Wire.h>
#include <Arduino.h>
//#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define BUTTON_PRESSED() (!digitalRead(34)) // Active
#define WIRE Wire
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
// #define H_SENSOR_ADDRESS MS8607_HSENSOR_ADDR //HSENSOR device address
// #define P_SENSOR_ADDRESS MS8607_PSENSOR_ADDR //PSENSOR device address
Adafruit_SSD1306 display = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &WIRE);
//TwoWire I2CPHT_1 = TwoWire(0);
// MS8607 barometricSensor;
uint32_t delayTime;
uint32_t i = 0;
// 'logov2', 128x32px
const unsigned char groAqua_logov2 [] PROGMEM = {
0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x75, 0x57, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xdd, 0xd5, 0xdd, 0xdd, 0xdd, 0xdd, 0xd5, 0x55, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfa, 0xab, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x70, 0x00, 0x17, 0x77, 0x77, 0x77, 0x75, 0x55, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
0xe0, 0x3e, 0x3f, 0xff, 0xff, 0xff, 0xf2, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc1, 0xdd, 0x1d, 0xdd, 0xdd, 0xdd, 0xd5, 0x55, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0x81, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xea, 0xea, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x03, 0x77, 0x57, 0x75, 0x77, 0x77, 0x75, 0x75, 0x77, 0x77, 0x77, 0x77, 0x77, 0x55, 0x77, 0x77,
0x83, 0xff, 0xf8, 0x18, 0xf0, 0x0f, 0xe2, 0xf2, 0x7f, 0x80, 0x10, 0x38, 0x1e, 0x00, 0x7f, 0xff,
0x05, 0xdd, 0xd8, 0x10, 0x40, 0x05, 0xd5, 0xd5, 0x5c, 0x00, 0x10, 0x18, 0x1c, 0x00, 0x1d, 0xdd,
0x07, 0xff, 0xfe, 0x00, 0x83, 0x83, 0xea, 0xfa, 0xbc, 0x0c, 0x18, 0x3e, 0x0e, 0x00, 0x3f, 0xff,
0x07, 0x77, 0x74, 0x05, 0x07, 0x41, 0x55, 0x75, 0x70, 0x34, 0x14, 0x16, 0x17, 0x74, 0x17, 0x77,
0x07, 0xff, 0xfe, 0x0f, 0x03, 0xc1, 0xa3, 0xfa, 0x38, 0x3c, 0x18, 0x3e, 0x0f, 0xfc, 0x1f, 0xff,
0x05, 0xd0, 0x04, 0x1d, 0x05, 0xc1, 0x55, 0xd5, 0x50, 0x5c, 0x1c, 0x1c, 0x1d, 0xdc, 0x1d, 0xdd,
0x07, 0xf0, 0x06, 0x0f, 0x07, 0xe0, 0xab, 0xfa, 0xb0, 0x7c, 0x18, 0x3e, 0x0f, 0x80, 0x1f, 0xff,
0x07, 0x74, 0x14, 0x17, 0x07, 0x41, 0x57, 0x75, 0x50, 0x74, 0x14, 0x16, 0x14, 0x00, 0x17, 0x77,
0x83, 0xfc, 0x1e, 0x0f, 0x07, 0xe1, 0x23, 0xfe, 0x38, 0x7c, 0x18, 0x3e, 0x0c, 0x0c, 0x1f, 0xff,
0x81, 0xdc, 0x1c, 0x1d, 0x05, 0xc1, 0x55, 0xdd, 0x50, 0x5c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1d, 0xdd,
0x81, 0xfc, 0x1e, 0x0f, 0x83, 0xc2, 0xaf, 0xfe, 0xa8, 0x7c, 0x18, 0x3e, 0x08, 0x3c, 0x1f, 0xff,
0x40, 0x74, 0x14, 0x17, 0x03, 0x41, 0x57, 0x75, 0x54, 0x34, 0x14, 0x14, 0x14, 0x14, 0x17, 0x77,
0xf0, 0x00, 0x18, 0x03, 0xc0, 0x02, 0x2f, 0xfe, 0x24, 0x0c, 0x1c, 0x00, 0x04, 0x00, 0x0f, 0xff,
0xdc, 0x00, 0x18, 0x05, 0xd0, 0x05, 0x55, 0xdd, 0x54, 0x04, 0x1c, 0x04, 0x04, 0x04, 0x05, 0xdd,
0xff, 0x82, 0xfe, 0xef, 0xf8, 0x3e, 0xaf, 0xfe, 0xab, 0x8c, 0x1f, 0x8e, 0xef, 0x8e, 0x0f, 0xff,
0x77, 0x77, 0x77, 0x77, 0x77, 0x75, 0x57, 0x77, 0x57, 0x74, 0x17, 0x77, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xdd, 0xdd, 0xdd, 0xdd, 0xd5, 0x55, 0x55, 0x55, 0x55, 0xdc, 0x1d, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xff, 0xff, 0xff, 0xfe, 0xaa, 0xaa, 0xaa, 0xaa, 0xab, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x77, 0x77, 0x77, 0x77, 0x77, 0x75, 0x55, 0x55, 0x57, 0x70, 0x07, 0x77, 0x77, 0x77, 0x77, 0x77,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe2, 0x22, 0x2f, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xd5, 0x55, 0x5d, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xea, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void setup() {
Serial.begin(9600);
Serial.println("OLED FeatherWing test");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
Serial.println("OLED begun");
display.clearDisplay();
display.drawBitmap(0,0, groAqua_logov2, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
display.display();
delay(1000);
display.clearDisplay();
//bool phtSensorStatus;
// Wire.begin();
// if (barometricSensor.begin() == false)
// {
// Serial.println("MS8607 sensor did not respond. Trying again...");
// if (barometricSensor.begin() == false)
// {
// Serial.println("MS8607 sensor did not respond. Please check wiring.");
// while (1)
// ;
// }
}
delayTime = 500;
}
void loop() {
float temperature = 10.0
float pressure = 30.5
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("Temperature: ");
display.print(temperature, 1);
display.print("(C)");
display.setCursor(0,8);
display.print("Pressure: ");
display.print(pressure, 1);
display.print("(hPa or mbar)");
display.display();
delay(500);
yield();
}
void drawGauge(float temperature, float pressure){
// Map the sensor values to pixel heights
int tempHeight = map(temperature, -10, 40, 0, SCREEN_HEIGHT);
int presHeight = map(pressure, 950, 1050, 0, SCREEN_HEIGHT);
// Draw temperature gauge
display.drawRoundRect(10, SCREEN_HEIGHT - tempHeight - 1, 20, tempHeight, 5, SSD1306_WHITE);
// Draw pressure gauge
display.drawRoundRect(50, SCREEN_HEIGHT - presHeight - 1, 20, presHeight, 5, SSD1306_WHITE);
}