Skip to content

Commit

Permalink
Added more demos
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed May 28, 2017
1 parent 4432fa9 commit 80f3700
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 0 deletions.
128 changes: 128 additions & 0 deletions examples/ILI9341/BasicDrawing/BasicDrawing.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
The MIT License (MIT)
Copyright (c) 2017 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Please note: I am spending a lot of my free time in developing Software and Hardware
for these projects. Please consider supporting me by
a) Buying my hardware kits from https://blog.squix.org/shop
b) Send a donation: https://www.paypal.me/squix/5USD
c) Or using this affiliate link while shopping: https://www.banggood.com/?p=6R31122484684201508S
See more at https://blog.squix.org
Demo for the buffered graphics library. Renders a 3D cube
*/

#include <SPI.h>
#include "MiniGrafx.h" // General graphic library
#include "ILI9341_SPI.h" // Hardware-specific library



#define TFT_DC D2
#define TFT_CS D1
#define TFT_LED D8

// defines the colors usable in the paletted 16 color frame buffer
uint16_t palette[] = {ILI9341_BLACK, // 0
ILI9341_WHITE, // 1
ILI9341_NAVY, // 2
ILI9341_DARKCYAN, // 3
ILI9341_DARKGREEN, // 4
ILI9341_MAROON, // 5
ILI9341_PURPLE, // 6
ILI9341_OLIVE, // 7
ILI9341_LIGHTGREY, // 8
0x39E7, //ILI9341_DARKGREY, // 9
ILI9341_BLUE, // 10
ILI9341_GREEN, // 11
ILI9341_CYAN, // 12
ILI9341_RED, // 13
ILI9341_MAGENTA, // 14
0xFD80}; // 15



int SCREEN_WIDTH = 240;
int SCREEN_HEIGHT = 320;
int BITS_PER_PIXEL = 4 ; // 2^4 = 16 colors

// Initialize the driver
ILI9341_SPI tft = ILI9341_SPI(TFT_CS, TFT_DC);
MiniGrafx gfx = MiniGrafx(&tft, SCREEN_WIDTH, SCREEN_HEIGHT, BITS_PER_PIXEL, palette);


// Used for fps measuring
uint16_t counter = 0;
long startMillis = millis();
uint16_t interval = 20;
int color = 1;
String fps = "0fps";

void setup() {
Serial.begin(115200);

// Turn on the background LED
pinMode(TFT_LED, OUTPUT);
digitalWrite(TFT_LED, HIGH);

gfx.init();
gfx.fillBuffer(0);
gfx.commit();


startMillis = millis();
}

int width = 20;

void loop() {

gfx.fillBuffer(0);

width = 20 + (counter % 20);

for(int y = 0; y < 320; y = y + width) {
for (int x = 0; x < 240; x = x + width) {
if ((x + y) % (width * 2) == 0) {
gfx.setColor(6);
gfx.fillRect(x, y, width, width);
} else {
gfx.setColor(7);
gfx.fillCircle(x + width / 2, y + width / 2, width / 2);
}
gfx.setColor(1);
gfx.drawLine(0, y, 240, y);
gfx.setColor(2);
gfx.drawLine(x, 0, x, 320);

}
}
gfx.setColor(15);
gfx.drawString(2, 2, fps);
gfx.commit();

counter++;
// only calculate the fps every <interval> iterations.
if (counter % interval == 0) {
color = (color + 1) % 15 + 1;
long millisSinceUpdate = millis() - startMillis;
fps = String(interval * 1000.0 / (millisSinceUpdate)) + "fps";
startMillis = millis();
}
}
83 changes: 83 additions & 0 deletions examples/ILI9341/DrawPaletteImage_4Bit/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const char img[] PROGMEM = {
0x01, // Version: 1
0x04, // BitDepth: 4
0x00, 0x9D, // Width: 157
0x00, 0x13, // Height: 19
// Round width to next byte: 160
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x11, 0x11,
0x11, 0x18, 0x88, 0x81, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x11, 0x11, 0x11, 0x11, 0x18, 0x88, 0x88,
0x88, 0x88, 0x88, 0x81, 0x11, 0x11, 0x11, 0x11, 0x18, 0x88, 0x88, 0x88, 0x11, 0x11, 0x11, 0x11, 0x18, 0x88, 0x88, 0x11,
0x11, 0x11, 0x11, 0x18, 0x88, 0x88, 0x88, 0x88, 0x88, 0x81, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x81, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x18, 0x88, 0x81, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x81, 0x11, 0x11, 0x10, 0x11, 0x11, 0x99,
0x00, 0x00, 0x00, 0x09, 0x81, 0x11, 0x11, 0x11, 0x18, 0x90, 0x00, 0x00, 0x09, 0x81, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x09, 0x11, 0x11, 0x11, 0x89, 0x00, 0x00, 0x00, 0x00, 0x81, 0x11, 0x11, 0x19, 0x90, 0x00, 0x00, 0x09, 0x81,
0x11, 0x18, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x98, 0x11, 0x11, 0x11,
0x11, 0x11, 0x89, 0x00, 0x00, 0x98, 0x11, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x98, 0x11, 0x10, 0x11, 0x19, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00,
0x00, 0x09, 0x81, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x11, 0x18, 0x90, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x89, 0x00, 0x00, 0x00, 0x00, 0x09, 0x81, 0x11, 0x11, 0x11,
0x19, 0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x10, 0x11, 0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x09, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x81, 0x18,
0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x11, 0x11, 0x11, 0x90,
0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x11, 0x90, 0x00, 0x98, 0x88, 0x89,
0x00, 0x00, 0x81, 0x11, 0x80, 0x00, 0x08, 0x88, 0x88, 0x90, 0x00, 0x91, 0x11, 0x88, 0x89, 0x00, 0x09, 0x88, 0x88, 0x88,
0x11, 0x18, 0x90, 0x00, 0x98, 0x88, 0x88, 0x88, 0x11, 0x11, 0x80, 0x00, 0x98, 0x88, 0x88, 0x90, 0x00, 0x91, 0x11, 0x88,
0x89, 0x00, 0x08, 0x88, 0x88, 0x88, 0x11, 0x18, 0x00, 0x09, 0x88, 0x88, 0x89, 0x00, 0x09, 0x11, 0x11, 0x18, 0x00, 0x00,
0x98, 0x88, 0x81, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x89, 0x00, 0x09, 0x10, 0x18, 0x00, 0x09, 0x81, 0x11, 0x11, 0x90,
0x00, 0x91, 0x11, 0x90, 0x00, 0x91, 0x11, 0x11, 0x19, 0x00, 0x98, 0x11, 0x11, 0x19, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11,
0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x81, 0x11, 0x11, 0x10, 0x00, 0x91, 0x11, 0x11, 0x19,
0x00, 0x91, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x18, 0x00, 0x09, 0x11, 0x11, 0x19, 0x00, 0x09, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x10, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00,
0x91, 0x11, 0x90, 0x00, 0x99, 0x99, 0x99, 0x90, 0x00, 0x08, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x19,
0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x99, 0x99, 0x99, 0x90, 0x00, 0x98, 0x11, 0x11, 0x19, 0x00,
0x91, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x09, 0x99, 0x99, 0x99, 0x00, 0x09, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x89, 0x99, 0x99, 0x99, 0x00, 0x00, 0x80, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91,
0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00,
0x08, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x11, 0x11, 0x19, 0x00, 0x91,
0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11,
0x11, 0x11, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11,
0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x11, 0x11, 0x19, 0x00, 0x91, 0x11,
0x11, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11,
0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11, 0x90,
0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x99, 0x99, 0x99, 0x99, 0x98, 0x11, 0x11, 0x11, 0x19, 0x00, 0x01, 0x11, 0x11,
0x11, 0x11, 0x19, 0x00, 0x09, 0x99, 0x99, 0x99, 0x99, 0x81, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x18,
0x00, 0x09, 0x99, 0x99, 0x99, 0x00, 0x00, 0x80, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11, 0x90, 0x00,
0x91, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x18, 0x00, 0x09, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x91, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11,
0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x19, 0x00,
0x08, 0x11, 0x11, 0x11, 0x90, 0x00, 0x80, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11, 0x80, 0x00, 0x09,
0x88, 0x88, 0x88, 0x81, 0x11, 0x11, 0x11, 0x19, 0x00, 0x09, 0x88, 0x88, 0x11, 0x11, 0x18, 0x90, 0x00, 0x98, 0x88, 0x88,
0x88, 0x11, 0x11, 0x80, 0x00, 0x08, 0x88, 0x88, 0x88, 0x81, 0x11, 0x11, 0x11, 0x19, 0x00, 0x09, 0x88, 0x88, 0x11, 0x11,
0x18, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x11, 0x11, 0x18, 0x89, 0x00, 0x09, 0x88, 0x88, 0x88, 0x11, 0x18, 0x00, 0x09,
0x88, 0x88, 0x89, 0x00, 0x00, 0x10, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11, 0x19, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x11, 0x11, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x91, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x09,
0x81, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x11, 0x11, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x81, 0x11, 0x11,
0x90, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x09, 0x10, 0x18, 0x00, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x91, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00,
0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x91, 0x11, 0x11, 0x19, 0x00, 0x00, 0x00, 0x00, 0x09, 0x81,
0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x11, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x91, 0x11, 0x11, 0x19,
0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x98, 0x10, 0x18, 0x90, 0x09, 0x11, 0x11, 0x11, 0x80, 0x00, 0x81, 0x11, 0x11, 0x18, 0x90, 0x00, 0x00, 0x00,
0x91, 0x11, 0x11, 0x11, 0x11, 0x18, 0x90, 0x00, 0x00, 0x81, 0x11, 0x11, 0x11, 0x89, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11,
0x11, 0x18, 0x90, 0x00, 0x00, 0x00, 0x98, 0x11, 0x11, 0x11, 0x11, 0x18, 0x90, 0x00, 0x00, 0x81, 0x11, 0x11, 0x11, 0x89,
0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x11, 0x11, 0x18, 0x90, 0x00, 0x00, 0x00,
0x09, 0x11, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

0 comments on commit 80f3700

Please sign in to comment.