Code:
// hw brickbench
// Adafruit ILI9340 / ILI9341
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
// for Due/Mega/Leonardo use the hardware SPI pins (which are different)
#define _cs 10
#define _dc 9
#define _rst 8
// Using software SPI is really not suggested, its incredibly slow
// Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
// Use hardware SPI
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
#define WHITE ILI9340_WHITE
#define TimerMS() millis()
unsigned long runtime[8];
void TFTprint(char sbuf[], int16_t x, int16_t y) {
tft.setCursor(x, y);
tft.print(sbuf);
}
inline void displayValues() {
char buf[120];
tft.fillScreen(ILI9340_BLACK); // clrscr()
sprintf (buf, "%3d %9ld int_Add", 0, runtime[0]); TFTprint(buf, 0,10);
sprintf (buf, "%3d %9ld int_Mult", 1, runtime[1]); TFTprint(buf, 0,20);
sprintf (buf, "%3d %9ld float_op", 2, runtime[2]); TFTprint(buf, 0,30);
sprintf (buf, "%3d %9ld randomize", 3, runtime[3]); TFTprint(buf, 0,40);
sprintf (buf, "%3d %9ld matrx_algb", 4, runtime[4]); TFTprint(buf, 0,50);
sprintf (buf, "%3d %9ld arr_sort", 5, runtime[5]); TFTprint(buf, 0,60);
sprintf (buf, "%3d %9ld TextOut", 6, runtime[6]); TFTprint(buf, 0,70);
sprintf (buf, "%3d %9ld Graphics", 7, runtime[7]); TFTprint(buf, 0,80);
}
int32_t test_TextOut(){
int y;
char buf[120];
for(y=0;y<20;++y) {
tft.fillScreen(ILI9340_BLACK); // clrscr()
sprintf (buf, "%3d %9d int_Add", y, 1000); TFTprint(buf, 0,10);
sprintf (buf, "%3d %9d int_Mult", 0, 1010); TFTprint(buf, 0,20);
sprintf (buf, "%3d %9d float_op", 0, 1020); TFTprint(buf, 0,30);
sprintf (buf, "%3d %9d randomize", 0, 1030); TFTprint(buf, 0,40);
sprintf (buf, "%3d %9d matrx_algb", 0, 1040); TFTprint(buf, 0,50);
sprintf (buf, "%3d %9d arr_sort", 0, 1050); TFTprint(buf, 0,60);
sprintf (buf, "%3d %9d displ_txt", 0, 1060); TFTprint(buf, 0,70);
sprintf (buf, "%3d %9d testing...", 0, 1070); TFTprint(buf, 0,80);
}
return y;
}
int32_t test_graphics(){
int y;
char buf[120];
for(y=0;y<100;++y) {
tft.fillScreen(ILI9340_BLACK);
sprintf (buf, "%3d", y); TFTprint(buf, 0,80); // outcomment for downwards compatibility
tft.drawCircle(50, 40, 10, WHITE);
tft.fillCircle(30, 24, 10, WHITE);
tft.drawLine(10, 10, 60, 60, WHITE);
tft.drawLine(50, 20, 90, 70, WHITE);
tft.drawRect(20, 20, 40, 40, WHITE);
tft.fillRect(65, 25, 20, 30, WHITE);
tft.drawEclipse(70, 30, 15, 20); // original test
// tft.drawCircle(70, 30, 15, WHITE); // alternatively, just if no drawEclipse is avaiable in the Arduino graph libs!
}
return y;
}
int test(){
unsigned long time0, x, y;
double s;
char buf[120];
int i;
float f;
// lcd display text / graphs
time0=TimerMS();
s=test_TextOut();
runtime[6]=TimerMS()-time0;
sprintf (buf, "%3d %9ld TextOut", 6, runtime[6]); Serial.println( buf);
TFTprint(buf, 0,70);
time0=TimerMS();
s=test_graphics();
runtime[7]=TimerMS()-time0;
sprintf (buf, "%3d %9ld Graphics", 7, runtime[7]); Serial.println( buf);
TFTprint(buf, 0,80);
Serial.println();
y = 0;
for (x = 0; x < 8; ++x) {
y += runtime[x];
}
displayValues();
sprintf (buf, "gesamt ms: %9ld ", y);
Serial.println( buf);
TFTprint(buf, 0,110);
x=50000000.0/y;
sprintf (buf, "benchmark: %9ld ", x);
Serial.println( buf);
TFTprint(buf, 0,120);
return 1;
}
void setup() {
Serial.begin(9600);
// Setup the LCD
tft.begin();
tft.setTextColor(ILI9340_WHITE); tft.setTextSize(1);
}
void loop() {
char buf[120];
test();
sprintf (buf, "Ende HaWe brickbench");
Serial.println( buf);
TFTprint(buf, 0, 140);
while(1);
}
Lesezeichen