#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN WIDTH 128
#define SCREEN HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(128,64, &Wire, OLED_RESET);
int p1 = random(0,100);
int p2 = random(0,100);
int p3 = random(0,100);
void setup() {
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
Serial.begin(9600);
}
void loop() {
display.clearDisplay(); //Clear Display
drawPercentbar( 6, 2, 50, 10,p1); //Draw Bar @ (Y=0, X=20, Length=100, p2=Start from which percentage"This test is start from random percentage, see line 11)
drawPercentbar( 0, 20, 100, 15, p2); //Draw Bar @ (Y=0, X=20, Length=100, p2=Start from which percentage"This test is start from random percentage, see line 12)
drawPercentbar( 0, 40, 128, 20,p3); //Draw Bar @ (Y=0, X=20, Length=100, p2=Start from which percentage"This test is start from random percentage, see line 13)
display.display();
p1++;p2++;p3++;
if( p1 > 100) p1 =0;
if( p2 > 100) p2 =0;
if( p3 > 100) p3 =0;
delay(100); //Control the speen of the percent bar
}
void drawPercentbar(int x,int y, int width,int height, int progress) {
//Here start made a persent bar
progress = progress > 100 ? 100 : progress;
progress = progress < 0 ? 0 : progress;
float bar = ((float)(width-4) / 100) * progress; //(wide-4 / 100) = Define the end of the bar at befor the frame
display.drawRect(x, y, width, height, WHITE); //Draw a rectangle
display.fillRect(x+2, y+2, bar , height-4, WHITE); //
//Here start made the persentage text
if( height >= 10){
display.setCursor((width/2) -6, y+4); //Text start @ ((X=width/2)-6,Y=Y+4)
display.setTextSize(1);
display.setTextColor(WHITE);
//When the percentage = "50%" then will invert the text color
if( progress >=50)
display.setTextColor(BLACK,WHITE); //(BLACK=Change text color to BLACK, WHITE=Change to WHITE color behine the text)
display.print(progress);
display.print("%");
}
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
oled1:DATA
oled1:CLK
oled1:DC
oled1:RST
oled1:CS
oled1:3V3
oled1:VIN
oled1:GND