/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-oled
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int value; //save analog value
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
delay(2000); // wait for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(2); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(0, 10); // position to display
oled.println("Hello World!"); // text to display
oled.display(); // show on OLED
}
void loop() { // draw rectangle
Serial.println(value);
value = analogRead(A0); //Read and save analog value from potentiometer
value = map(value, 0, 1023, 0, 460);
if(value>=350 && value<400){
oled.clearDisplay();
oled.drawRect(30, 5, 60, 25, WHITE);//droit-gauche,haut-bas,largeur,hauteur
oled.drawRect(20, 12, 10, 10, WHITE);
oled.drawRect(85, 5, 1, 25, WHITE);
oled.drawRect(80, 5, 1, 25, WHITE);
oled.drawRect(75, 5, 1, 25, WHITE);
oled.drawRect(70, 5, 1, 25, WHITE);
oled.drawRect(65, 5, 1, 25, WHITE);
oled.drawRect(60, 5, 1, 25, WHITE);
oled.drawRect(55, 5, 1, 25, WHITE);
oled.drawRect(50, 5, 1, 25, WHITE);
oled.display();
delay(2000);
}
if(value>=400){
oled.clearDisplay();
oled.drawRect(30, 5, 60, 25, WHITE);//droit-gauche,haut-bas,largeur,hauteur
oled.drawRect(20, 12, 10, 10, WHITE);
oled.drawRect(85, 5, 1, 25, WHITE);
oled.drawRect(80, 5, 1, 25, WHITE);
oled.drawRect(75, 5, 1, 25, WHITE);
oled.drawRect(70, 5, 1, 25, WHITE);
oled.drawRect(65, 5, 1, 25, WHITE);
oled.drawRect(60, 5, 1, 25, WHITE);
oled.drawRect(55, 5, 1, 25, WHITE);
oled.drawRect(50, 5, 1, 25, WHITE);
oled.drawRect(45, 5, 1, 25, WHITE);
oled.drawRect(40, 5, 1, 25, WHITE);
oled.drawRect(35, 5, 1, 25, WHITE);
oled.display();
delay(2000);
}
if(value<350 && value>300){
oled.clearDisplay();
oled.drawRect(30, 5, 60, 25, WHITE);//droit-gauche,haut-bas,largeur,hauteur
oled.drawRect(20, 12, 10, 10, WHITE);
oled.drawRect(85, 5, 1, 25, WHITE);
oled.drawRect(80, 5, 1, 25, WHITE);
oled.drawRect(75, 5, 1, 25, WHITE);
oled.drawRect(70, 5, 1, 25, WHITE);
oled.drawRect(65, 5, 1, 25, WHITE);
oled.display();
delay(2000);
}
if(value>250 && value <=300){
oled.clearDisplay();
oled.drawRect(30, 5, 60, 25, WHITE);//droit-gauche,haut-bas,largeur,hauteur
oled.drawRect(20, 12, 10, 10, WHITE);
oled.drawRect(85, 5, 1, 25, WHITE);
oled.drawRect(80, 5, 1, 25, WHITE);
oled.display();
delay(2000);
}
if(value<250){
oled.clearDisplay();
oled.drawRect(30, 5, 60, 25, WHITE);//droit-gauche,haut-bas,largeur,hauteur
oled.drawRect(20, 12, 10, 10, WHITE);
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(34, 12); // position to display
oled.println("RECHARGE");
oled.display();
delay(500);
oled.clearDisplay();
oled.display();
delay(500);
}
}