/*********************************************************************
This sketch controls an electronic circuit that can sense
the environment using a sensor (electronic components that convert
real-world measurements into electrical signals). The device
processes the information from the sensors with the behavior
described in the sketch. The device will then be able to interact
with the world by using actuators, electronic components that can
convert an electric signal into physical action.
EETechFix
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // display width, in pixels
#define SCREEN_HEIGHT 64 // display height, in pixels
#define OLED_RESET 4
#define SCREEN_ADDRESS 0x3D // OLED
const int sensorPin = A0;
const float alpha = 0.95; // Low Pass Filter alpha (0 - 1 )
const float aRef = 4.6; // analog reference
float filteredVal = 512.0; // midway starting point
float adcVal;
float voltage;
float psiVal;
float P1,P2,P3,P4,P5;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
while (!Serial);
//analogReference(EXTERNAL);
//analogReference(INTERNAL);
//SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
while (1); // Don't proceed, wait forever
}
display.clearDisplay();
display.display();
}
void loop() {
adcVal = (float)analogRead(A0); // Read pressure sensor val (A0)
voltage = (adcVal / 1024.0) * aRef; // calculate voltage
P1 = (voltage - 0.4784) / 0.0401; // x=(y-b)/m
adcVal = (float)analogRead(A1); // Read pressure sensor val (A0)
voltage = (adcVal / 1024.0) * aRef; // calculate voltage
P2 = (voltage - 0.4784) / 0.0401; // x=(y-b)/m
adcVal = (float)analogRead(A2); // Read pressure sensor val (A0)
voltage = (adcVal / 1024.0) * aRef; // calculate voltage
P3 = (voltage - 0.4784) / 0.0401; // x=(y-b)/m
adcVal = (float)analogRead(A3); // Read pressure sensor val (A0)
voltage = (adcVal / 1024.0) * aRef; // calculate voltage
P4 = (voltage - 0.4784) / 0.0401; // x=(y-b)/m
adcVal = (float)analogRead(A6); // Read pressure sensor val (A0)
voltage = (adcVal / 1024.0) * aRef; // calculate voltage
P5 = (voltage - 0.4784) / 0.0401; // x=(y-b)/m
updateOLED ();
delay(200);
}
void updateOLED () {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 3);
display.print("P1= "); display.print(P1, 0);display.print(" psi");
display.setCursor(10, 15);
display.print("P2= "); display.print(P2, 0);display.print(" psi");
display.setCursor(10, 27);
display.print("P3= ");display.print(P3, 0);display.print(" psi");
display.setCursor(10, 39);
display.print("P4= "); display.print(P4, 0);display.print(" psi");
display.setCursor(10, 51);
display.print("P5= "); display.print(P5, 0);display.print(" psi");
display.display();
}