In the code above you see the method display.drawProgressBar() being used. It takes 5 arguments. The first two arguments are the x and y coordinates of the progress bar. The next two arguments are the width and height of the progress bar. And the final argument is the progress in percentage. It takes a number between 1 and 100 and draws the progress bar accordingly.
Next, let us look at drawing geometric shapes on the OLED display.
//Include the necessary libraries
//Declare the display
//I2C address is 0x3c
SH1106Wire display(0x3c, D2, D1);
// Initialize the display
//if you want to invert the display
//clear the display
//draw a line
display.drawLine(0, 0, 60, 35);
//draw a rectangle both filled and hollow
display.fillRect(20, 40, 25, 15);
display.drawRect(0, 25, 15, 25);
//draw a circle both filled and hollow and quadrant
display.fillCircle(60, 15, 10);
display.drawCircle(90, 15, 15);
display.drawCircleQuads(80, 35, 20, 0x8);
//write the buffer to the display
In the code above you can notice the various functions that are being used for the geometric shapes.
display.drawLine(x1, y1, x2, y2) - the first two parameters are the x and y coordinates of the starting point of the line and next two parameters are the x and y coordinates of the terminating point of the line
display.drawRect(x, y, w, h) - here the first two parameters are the x and y coordinates of the top left vertex of the rectangle. The next two parameters are the width and height of the rectangle in pixels. display fillRect() method also uses the same parameters list.
display.drawCircle(x0, y0, r) - here the first two parameters are the x and y coordinates of the circle. The last parameter is the radius of the circle in pixels. The display.fillCircle() method also uses the same parameters list.
display.drawCircleQuads(x0, y0, r, q) - here the first three parameters are the same as the drawCircle() method. The last parameter q is the quads bit mask which specifies the quadrants to be drawn.
Let us look into displaying animations on the OLED display now. For this, you need an array of images which when played in succession will appear as a video or an animation. One sample animation is included in the header file “anim1.h”. Download it from the link given below and place it in the same directory as your main file so that it can be included.
Here the anim.h header file contains the anim1 variable which is an array of images which are displayed sequentially. The variable num_frames is also present in this header file and defines the number of frames present in the video, once the sequence is completed it starts from the beginning.