#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*
* Connections
* SSD1306 OLED | Arduino Uno
* ---------------------------
* VCC | +5V (Vcc/power/+ve)
* GND | GND (Ground/-ve/0v)
* SCL | A5 (Serial Clock Line)
* SDA | A4 (Serial Data Line)
*/
const int SCREEN_WIDTH = 128; // OLED display width, in pixels
const int SCREEN_HEIGHT = 64; // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
float clamp(float x, float lower_limit = 0.0f ,float uper_limit = 1.0f){
if(x < lower_limit )return lower_limit;
if(x > uper_limit )return uper_limit;
return x;
}
float smoothstep(float x, float edge0= 0.0f ,float edge1 = 1.0f){
x =clamp((x-edge0)/(edge1-edge0));
return x*x*(3.0f - 2.0f * x);
}
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
while(true);
}
}
int progress_inc = 1;
int32_t progress =0;
int32_t adj_progress =0;
void loop() {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.drawCircle(64, 60, 49, SSD1306_WHITE);
display.drawCircle(64, 60, 47, SSD1306_WHITE);
display.drawCircle(64, 60, 6, SSD1306_WHITE);
display.drawCircle(64, 60, 2, SSD1306_WHITE);
progress = progress +progress_inc;
if(progress>=180 && progress_inc>0){
progress=180;
progress_inc = progress_inc * -1;
}
else if(progress <=0 && progress_inc <0){
progress=0;
progress_inc = progress_inc * -1;
}
adj_progress = (progress/180.0)*100.0;
adj_progress= smoothstep(adj_progress,0,100)*180;
int startx_OFF = round(-cos(radians(adj_progress+90)));
int starty_OFF = round(-sin(radians(adj_progress+90)));
int endx =round(-cos(radians(adj_progress))*40);
int endy= round(-sin(radians(adj_progress))*40);;
display.drawLine(64+startx_OFF,60+starty_OFF, 64+endx, 60+endy, SSD1306_WHITE);
display.drawLine(64+startx_OFF+1,60+starty_OFF, 64+endx+1, 60+endy, SSD1306_WHITE);
display.drawLine(64-startx_OFF, 60-starty_OFF, 64+endx, 60+endy, SSD1306_WHITE);
display.drawLine(64-startx_OFF+1, 60-starty_OFF, 64+endx+1, 60+endy, SSD1306_WHITE);
display.setCursor(54, 32);
// Display static text
display.print(progress);
display.display();
}