#include <Arduino.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R2);
int boostPressure;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 50;
void readSensorData(void)
{
float absolutePressure = analogRead(A3);
boostPressure = map(absolutePressure, 102, 921, 0, 3000) - 1000;
}
void setup(void)
{
u8g2.begin();
startMillis = millis();
}
void loop(void)
{
// Only read from the sensors every 50 ms
currentMillis = millis();
if (currentMillis - startMillis >= period)
{
readSensorData();
startMillis = currentMillis;
}
u8g2.firstPage();
do
{
// Draw current pressure
u8g2.setFont(u8g2_font_fub25_tf);
char cstr[6];
dtostrf((float)boostPressure / 1000, 1, 3, cstr);
u8g2.drawStr(0, 50, cstr);
}
while ( u8g2.nextPage() );
}