/*
* FPS benchmark
*
* Basic test code for the Arduino GLCD library.
* This code exercises a range of graphic functions supported
* by the library and provides examples of its use.
* It also gives an indication of performance, showing the
* number of frames drawn per second.
*/
#include <glcd.h>
#include "fonts/allFonts.h" // system and arial14 fonts are used
unsigned long startMillis;
unsigned int loops = 0;
unsigned int iter = 0;
void setup()
{
GLCD.Init(); // initialise the library, non inverted writes pixels onto a clear screen
GLCD.ClearScreen();
GLCD.SelectFont(System5x7, BLACK); // font for the default text area
}
void loop()
{
iter=0;
startMillis = millis();
while(iter++ < 10){ // do 10 iterations
GLCD.DrawRect(0, 0, GLCD.CenterX, GLCD.Bottom); // rectangle in left side of screen
GLCD.DrawRoundRect(GLCD.CenterX + 2, 0, GLCD.CenterX - 3, GLCD.Bottom, 5); // rounded rectangle around text area
for(int i=0; i < GLCD.Bottom; i += 4)
GLCD.DrawLine(1,1, GLCD.CenterX-1, i); // draw lines from upper left down right side of rectangle
GLCD.DrawCircle(GLCD.CenterX/2, GLCD.CenterY-1, min(GLCD.CenterX/2, GLCD.CenterY)-2); // draw circle centered in the left side of screen
GLCD.FillRect( GLCD.CenterX + GLCD.CenterX/2-8 ,GLCD.CenterY + GLCD.CenterY/2 -8,16,16, WHITE); // clear previous spinner position
drawSpinner(loops++, GLCD.CenterX + GLCD.CenterX/2, GLCD.CenterY + GLCD.CenterY/2); // draw new spinner position
GLCD.CursorToXY(GLCD.CenterX/2, GLCD.Bottom -15);
GLCD.print(iter); // print current iteration at the current cursor position
}
// display iterations per second
unsigned long duration = millis() - startMillis;
int fps = 10000 / duration;
int fps_fract = (10000 % duration) * 10 / (duration/10);
GLCD.ClearScreen(); // clear the screen
GLCD.CursorToXY(GLCD.CenterX + 16, 9);
GLCD.print("GLCD ");
GLCD.print(GLCD_VERSION, DEC);
if(GLCD.Height <= 32)
GLCD.CursorToXY(GLCD.CenterX + 4, 1);
else
GLCD.CursorToXY(GLCD.CenterX + 4, 24);
GLCD.print("FPS="); // print a text string
GLCD.print(fps); // print an integer value
GLCD.print(".");
if(fps_fract < 10)
GLCD.print((int)0); // have to manually print the leading 0 when necessary
GLCD.print(fps_fract);
}
void drawSpinner(byte pos, byte x, byte y)
{
// this draws an object that appears to spin
switch(pos % 8) {
case 0 : GLCD.DrawLine( x, y-8, x, y+8); break;
case 1 : GLCD.DrawLine( x+3, y-7, x-3, y+7); break;
case 2 : GLCD.DrawLine( x+6, y-6, x-6, y+6); break;
case 3 : GLCD.DrawLine( x+7, y-3, x-7, y+3); break;
case 4 : GLCD.DrawLine( x+8, y, x-8, y); break;
case 5 : GLCD.DrawLine( x+7, y+3, x-7, y-3); break;
case 6 : GLCD.DrawLine( x+6, y+6, x-6, y-6); break;
case 7 : GLCD.DrawLine( x+3, y+7, x-3, y-7); break;
}
}
posted by Copyright (C) avrin All Rights Reserved. at 22:35| Comment(0)
| LCD
|
|