//WORKING GOOD BEST..
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//#include <Fonts/FreeSansBoldOblique12pt7b.h>
//#include <Fonts/FreeSerifItalic9pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
//#include <Fonts/FreeSans18pt7b.h>
//#include <Fonts/FreeMonoOblique12pt7b.h>
//#include <Fonts/FreeMono24pt7b.h>
//#include <Fonts/FreeSansBold9pt7b.h>
//#include <Fonts/FreeSansBold18pt7b.h>
//#include <Fonts/FreeSerifItalic18pt7b.h>
//#include <Fonts/FreeMono12pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // 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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int ledPin1 = 5;
int potPin = A1;
int ledPin2 = 6;
int batPin = A2;
int potIn; // variable to store the value coming from the potentiometer
int batIn; // variable to store the value coming from the battery
int brightness1; // variable to hold the pwm value1
int brightness2; // variable to hold the pwm value2
void setup() {
Serial.begin(57600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop()
{
display.clearDisplay();
display.setFont(&FreeSansBold9pt7b);
display.invertDisplay(false);
display.setCursor(0, 20);
display.print("Output:");
display.setFont(&FreeSansBold12pt7b);
display.setCursor(68, 22);
display.print(brightness1);
display.print("%");
display.setFont(&FreeSansBold9pt7b);
display.setCursor(0, 54);
display.print("Battery:");
display.setFont(&FreeSansBold12pt7b);
display.setCursor(68, 56);
display.print(brightness2);
display.print("%");
display.display();
{
potIn = analogRead(potPin); //reading from potentiometer
{
potIn = map(potIn, 0, 1023, 0, 255); //mapping the Values between 0 to 255
analogWrite(ledPin1, potIn);
brightness1 = map(potIn, 0, 253, 0, 100); //mapping the Values between 0 to 100
delay (10);
}
batIn = analogRead(batPin); //reading from battery
{
batIn = map(batIn, 0, 1023, 0, 255); //mapping the Values between 0 to 255
analogWrite(ledPin2, batIn);
brightness2 = map(batIn, 0, 253, 0, 100); //mapping the Values between 0 to 100
delay (10);
}
}
}