#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//my
int mapPin = A1;
int mapVal;
int mapAccuracy = 3;
int mapAccuracyDelay = 5;
float mapBarPressure;
//int mapBarPressure;
int offset = 102; // zero pressure adjust
int fullScale = 922; // max pressure (span) adjust
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
//display.drawPixel(10, 10, SSD1306_WHITE);
display.setTextSize(3); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println("hello");
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(1000);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
display.clearDisplay(); // Clear display buffer
}
void loop() {
// put your main code here, to run repeatedly:
//mapVal1 = analogRead(mapPin);
//delay(10);
//mapVal2 = analogRead(mapPin);
//mapVal = (mapVal1 + mapVal2) / 2 ;
for (int i=0;i<mapAccuracy;i++){
mapVal += analogRead(mapPin);
delay(mapAccuracyDelay);
}
mapVal /= mapAccuracy;
//mapBarPressure = map(mapVal, 0, 1023, 0, 100);
mapBarPressure = (mapVal - offset) * 4.0 / (fullScale - offset); // conversion
//display.clearDisplay(); // Clear display buffer
display.setTextSize(3); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println(mapBarPressure, 1);
display.setTextSize(1);
display.println("Bar Boost");
//display.println(F("Hello, world!"));
display.display();
delay(10);
display.clearDisplay();
}