#include <Wire.h>
#include <math.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // set position to display (x,y)
oled.println("Robotronix"); // set text
oled.display(); // display on OLED
}
int cnt1 = 0;
float datFlt = 0.00;
float mVal = 3687.1400;
float hVal = -0.060757; //negative
float kVal = 43.950600;
float g = 9.81;
float areas = 1.53;
float toKg = 1000;
long datLng = 0.00;
void loop() {
cnt1+=100;
datFlt = (double)(((mVal*(sq(((float)cnt1/(float)(4096))-hVal)))+kVal)*g/(areas*toKg));
datLng = (long)(cnt1/4096);
//datFlt = (float)cnt1/(float)(4096);
String datStr = String(cnt1);
String datStr2 = String(datFlt, 5);
oled.clearDisplay(); // clear display
oled.setCursor(0, 2); // set position to display (x,y)
oled.println("Robotronix"); // set text
oled.setCursor(0, 30); // set position to display (x,y)
oled.println(datStr); // set text
oled.setCursor(0, 40); // set position to display (x,y)
oled.println(datStr2); // set text
oled.display(); // display on OLED
delay(1000);
}