mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-01 03:47:23 +03:00
* miss to add the new files
This commit is contained in:
@ -0,0 +1,145 @@
|
||||
/***************************************************
|
||||
This is our touchscreen painting example for the Adafruit ILI9341 Breakout
|
||||
----> http://www.adafruit.com/products/1770
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
/** NOT FOR USE WITH THE TOUCH SHIELD, ONLY FOR THE BREAKOUT! **/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_ILI9341.h>
|
||||
#include "TouchScreen.h"
|
||||
|
||||
// These are the four touchscreen analog pins
|
||||
#define YP A2 // must be an analog pin, use "An" notation!
|
||||
#define XM A3 // must be an analog pin, use "An" notation!
|
||||
#define YM 5 // can be a digital pin
|
||||
#define XP 4 // can be a digital pin
|
||||
|
||||
// This is calibration data for the raw touch data to the screen coordinates
|
||||
#define TS_MINX 150
|
||||
#define TS_MINY 120
|
||||
#define TS_MAXX 920
|
||||
#define TS_MAXY 940
|
||||
|
||||
#define MINPRESSURE 10
|
||||
#define MAXPRESSURE 1000
|
||||
|
||||
// The display uses hardware SPI, plus #9 & #10
|
||||
#define TFT_CS 10
|
||||
#define TFT_DC 9
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
// For better pressure precision, we need to know the resistance
|
||||
// between X+ and X- Use any multimeter to read it
|
||||
// For the one we're using, its 300 ohms across the X plate
|
||||
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
|
||||
|
||||
// Size of the color selection boxes and the paintbrush size
|
||||
#define BOXSIZE 40
|
||||
#define PENRADIUS 3
|
||||
int oldcolor, currentcolor;
|
||||
|
||||
void setup(void) {
|
||||
// while (!Serial); // used for leonardo debugging
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("Touch Paint!"));
|
||||
|
||||
tft.begin();
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
// make the color selection boxes
|
||||
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
|
||||
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
|
||||
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
|
||||
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
|
||||
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
|
||||
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
|
||||
|
||||
// select the current color 'red'
|
||||
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
currentcolor = ILI9341_RED;
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Retrieve a point
|
||||
TSPoint p = ts.getPoint();
|
||||
|
||||
/*
|
||||
Serial.print("X = "); Serial.print(p.x);
|
||||
Serial.print("\tY = "); Serial.print(p.y);
|
||||
Serial.print("\tPressure = "); Serial.println(p.z);
|
||||
*/
|
||||
|
||||
// we have some minimum pressure we consider 'valid'
|
||||
// pressure of 0 means no pressing!
|
||||
if (p.z < MINPRESSURE || p.z > MAXPRESSURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Scale from ~0->1000 to tft.width using the calibration #'s
|
||||
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
|
||||
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
|
||||
|
||||
/*
|
||||
Serial.print("("); Serial.print(p.x);
|
||||
Serial.print(", "); Serial.print(p.y);
|
||||
Serial.println(")");
|
||||
*/
|
||||
|
||||
|
||||
if (p.y < BOXSIZE) {
|
||||
oldcolor = currentcolor;
|
||||
|
||||
if (p.x < BOXSIZE) {
|
||||
currentcolor = ILI9341_RED;
|
||||
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*2) {
|
||||
currentcolor = ILI9341_YELLOW;
|
||||
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*3) {
|
||||
currentcolor = ILI9341_GREEN;
|
||||
tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*4) {
|
||||
currentcolor = ILI9341_CYAN;
|
||||
tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*5) {
|
||||
currentcolor = ILI9341_BLUE;
|
||||
tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*6) {
|
||||
currentcolor = ILI9341_MAGENTA;
|
||||
tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
}
|
||||
|
||||
if (oldcolor != currentcolor) {
|
||||
if (oldcolor == ILI9341_RED)
|
||||
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
|
||||
if (oldcolor == ILI9341_YELLOW)
|
||||
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
|
||||
if (oldcolor == ILI9341_GREEN)
|
||||
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
|
||||
if (oldcolor == ILI9341_CYAN)
|
||||
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
|
||||
if (oldcolor == ILI9341_BLUE)
|
||||
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
|
||||
if (oldcolor == ILI9341_MAGENTA)
|
||||
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
|
||||
}
|
||||
}
|
||||
if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
|
||||
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
|
||||
}
|
||||
}
|
@ -0,0 +1,349 @@
|
||||
/***************************************************
|
||||
This is our GFX example for the Adafruit ILI9341 Breakout and Shield
|
||||
----> http://www.adafruit.com/products/1651
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
|
||||
#include "SPI.h"
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ILI9341.h"
|
||||
|
||||
// For the Adafruit shield, these are the default.
|
||||
#define TFT_DC 9
|
||||
#define TFT_CS 10
|
||||
|
||||
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
// If using the breakout, change pins as desired
|
||||
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("ILI9341 Test!");
|
||||
|
||||
tft.begin();
|
||||
|
||||
// read diagnostics (optional but can help debug problems)
|
||||
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
|
||||
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDMADCTL);
|
||||
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDPIXFMT);
|
||||
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDIMGFMT);
|
||||
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDSELFDIAG);
|
||||
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
|
||||
|
||||
Serial.println(F("Benchmark Time (microseconds)"));
|
||||
|
||||
Serial.print(F("Screen fill "));
|
||||
Serial.println(testFillScreen());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Text "));
|
||||
Serial.println(testText());
|
||||
delay(3000);
|
||||
|
||||
Serial.print(F("Lines "));
|
||||
Serial.println(testLines(ILI9341_CYAN));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Horiz/Vert Lines "));
|
||||
Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rectangles (outline) "));
|
||||
Serial.println(testRects(ILI9341_GREEN));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rectangles (filled) "));
|
||||
Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Circles (filled) "));
|
||||
Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
|
||||
|
||||
Serial.print(F("Circles (outline) "));
|
||||
Serial.println(testCircles(10, ILI9341_WHITE));
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Triangles (outline) "));
|
||||
Serial.println(testTriangles());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Triangles (filled) "));
|
||||
Serial.println(testFilledTriangles());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rounded rects (outline) "));
|
||||
Serial.println(testRoundRects());
|
||||
delay(500);
|
||||
|
||||
Serial.print(F("Rounded rects (filled) "));
|
||||
Serial.println(testFilledRoundRects());
|
||||
delay(500);
|
||||
|
||||
Serial.println(F("Done!"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop(void) {
|
||||
for(uint8_t rotation=0; rotation<4; rotation++) {
|
||||
tft.setRotation(rotation);
|
||||
testText();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long testFillScreen() {
|
||||
unsigned long start = micros();
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
tft.fillScreen(ILI9341_RED);
|
||||
tft.fillScreen(ILI9341_GREEN);
|
||||
tft.fillScreen(ILI9341_BLUE);
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testText() {
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
unsigned long start = micros();
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
|
||||
tft.println(1234.56);
|
||||
tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
|
||||
tft.println(0xDEADBEEF, HEX);
|
||||
tft.println();
|
||||
tft.setTextColor(ILI9341_GREEN);
|
||||
tft.setTextSize(5);
|
||||
tft.println("Groop");
|
||||
tft.setTextSize(2);
|
||||
tft.println("I implore thee,");
|
||||
tft.setTextSize(1);
|
||||
tft.println("my foonting turlingdromes.");
|
||||
tft.println("And hooptiously drangle me");
|
||||
tft.println("with crinkly bindlewurdles,");
|
||||
tft.println("Or I will rend thee");
|
||||
tft.println("in the gobberwarts");
|
||||
tft.println("with my blurglecruncheon,");
|
||||
tft.println("see if I don't!");
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testLines(uint16_t color) {
|
||||
unsigned long start, t;
|
||||
int x1, y1, x2, y2,
|
||||
w = tft.width(),
|
||||
h = tft.height();
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
x1 = y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t = micros() - start; // fillScreen doesn't count against timing
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
x1 = 0;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height();
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
|
||||
for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testRects(uint16_t color) {
|
||||
unsigned long start;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2,
|
||||
cy = tft.height() / 2;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=2; i<n; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start, t = 0;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
for(i=n; i>0; i-=6) {
|
||||
i2 = i / 2;
|
||||
start = micros();
|
||||
tft.fillRect(cx-i2, cy-i2, i, i, color1);
|
||||
t += micros() - start;
|
||||
// Outlines are not included in timing results
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color2);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(x=radius; x<w; x+=r2) {
|
||||
for(y=radius; y<h; y+=r2) {
|
||||
tft.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, r2 = radius * 2,
|
||||
w = tft.width() + radius,
|
||||
h = tft.height() + radius;
|
||||
|
||||
// Screen is not cleared for this one -- this is
|
||||
// intentional and does not affect the reported time.
|
||||
start = micros();
|
||||
for(x=0; x<w; x+=r2) {
|
||||
for(y=0; y<h; y+=r2) {
|
||||
tft.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testTriangles() {
|
||||
unsigned long start;
|
||||
int n, i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(cx, cy);
|
||||
start = micros();
|
||||
for(i=0; i<n; i+=5) {
|
||||
tft.drawTriangle(
|
||||
cx , cy - i, // peak
|
||||
cx - i, cy + i, // bottom left
|
||||
cx + i, cy + i, // bottom right
|
||||
tft.color565(0, 0, i));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledTriangles() {
|
||||
unsigned long start, t = 0;
|
||||
int i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(i=min(cx,cy); i>10; i-=5) {
|
||||
start = micros();
|
||||
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(0, i, i));
|
||||
t += micros() - start;
|
||||
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(i, i, 0));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testRoundRects() {
|
||||
unsigned long start;
|
||||
int w, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
w = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=0; i<w; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRoundRects() {
|
||||
unsigned long start;
|
||||
int i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
|
||||
i2 = i / 2;
|
||||
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
@ -0,0 +1,341 @@
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_ILI9341.h>
|
||||
|
||||
// For the Adafruit shield, these are the default.
|
||||
#define TFT_DC 4
|
||||
#define TFT_CS 5
|
||||
|
||||
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
#define SERIAL_OUT Serial
|
||||
|
||||
unsigned long testFillScreen() {
|
||||
unsigned long start = micros();
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
tft.fillScreen(ILI9341_RED);
|
||||
tft.fillScreen(ILI9341_GREEN);
|
||||
tft.fillScreen(ILI9341_BLUE);
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testText() {
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
unsigned long start = micros();
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
|
||||
tft.println(1234.56);
|
||||
tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
|
||||
tft.println(0xDEADBEEF, HEX);
|
||||
tft.println();
|
||||
tft.setTextColor(ILI9341_GREEN);
|
||||
tft.setTextSize(5);
|
||||
tft.println("Groop");
|
||||
tft.setTextSize(2);
|
||||
tft.println("I implore thee,");
|
||||
tft.setTextSize(1);
|
||||
tft.println("my foonting turlingdromes.");
|
||||
tft.println("And hooptiously drangle me");
|
||||
tft.println("with crinkly bindlewurdles,");
|
||||
tft.println("Or I will rend thee");
|
||||
tft.println("in the gobberwarts");
|
||||
tft.println("with my blurglecruncheon,");
|
||||
tft.println("see if I don't!");
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testLines(uint16_t color) {
|
||||
unsigned long start, t;
|
||||
int x1, y1, x2, y2,
|
||||
w = tft.width(),
|
||||
h = tft.height();
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
delay(0);
|
||||
|
||||
x1 = y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t = micros() - start; // fillScreen doesn't count against timing
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
delay(0);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
delay(0);
|
||||
|
||||
x1 = 0;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
delay(0);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height();
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
|
||||
for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testRects(uint16_t color) {
|
||||
unsigned long start;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2,
|
||||
cy = tft.height() / 2;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=2; i<n; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start, t = 0;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
for(i=n; i>0; i-=6) {
|
||||
delay(0);
|
||||
i2 = i / 2;
|
||||
start = micros();
|
||||
tft.fillRect(cx-i2, cy-i2, i, i, color1);
|
||||
t += micros() - start;
|
||||
// Outlines are not included in timing results
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color2);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(x=radius; x<w; x+=r2) {
|
||||
for(y=radius; y<h; y+=r2) {
|
||||
tft.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, r2 = radius * 2,
|
||||
w = tft.width() + radius,
|
||||
h = tft.height() + radius;
|
||||
|
||||
// Screen is not cleared for this one -- this is
|
||||
// intentional and does not affect the reported time.
|
||||
start = micros();
|
||||
for(x=0; x<w; x+=r2) {
|
||||
for(y=0; y<h; y+=r2) {
|
||||
tft.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testTriangles() {
|
||||
unsigned long start;
|
||||
int n, i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
n = min(cx, cy);
|
||||
start = micros();
|
||||
for(i=0; i<n; i+=5) {
|
||||
tft.drawTriangle(
|
||||
cx , cy - i, // peak
|
||||
cx - i, cy + i, // bottom left
|
||||
cx + i, cy + i, // bottom right
|
||||
tft.color565(0, 0, i));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledTriangles() {
|
||||
unsigned long start, t = 0;
|
||||
int i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(i=min(cx,cy); i>10; i-=5) {
|
||||
start = micros();
|
||||
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(0, i, i));
|
||||
t += micros() - start;
|
||||
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(i, i, 0));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testRoundRects() {
|
||||
unsigned long start;
|
||||
int w, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
w = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for(i=0; i<w; i+=6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
|
||||
delay(0);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRoundRects() {
|
||||
unsigned long start;
|
||||
int i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
start = micros();
|
||||
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
|
||||
i2 = i / 2;
|
||||
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
|
||||
delay(0);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
SERIAL_OUT.begin(921600);
|
||||
SERIAL_OUT.println("ILI9341 Test!");
|
||||
|
||||
tft.begin();
|
||||
|
||||
// read diagnostics (optional but can help debug problems)
|
||||
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
|
||||
SERIAL_OUT.print("Display Power Mode: 0x"); SERIAL_OUT.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDMADCTL);
|
||||
SERIAL_OUT.print("MADCTL Mode: 0x"); SERIAL_OUT.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDPIXFMT);
|
||||
SERIAL_OUT.print("Pixel Format: 0x"); SERIAL_OUT.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDIMGFMT);
|
||||
SERIAL_OUT.print("Image Format: 0x"); SERIAL_OUT.println(x, HEX);
|
||||
x = tft.readcommand8(ILI9341_RDSELFDIAG);
|
||||
SERIAL_OUT.print("Self Diagnostic: 0x"); SERIAL_OUT.println(x, HEX);
|
||||
|
||||
SERIAL_OUT.println(F("Benchmark Time (microseconds)"));
|
||||
|
||||
SERIAL_OUT.print(F("Screen fill "));
|
||||
SERIAL_OUT.println(testFillScreen());
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Text "));
|
||||
SERIAL_OUT.println(testText());
|
||||
delay(3000);
|
||||
|
||||
SERIAL_OUT.print(F("Lines "));
|
||||
SERIAL_OUT.println(testLines(ILI9341_CYAN));
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Horiz/Vert Lines "));
|
||||
SERIAL_OUT.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Rectangles (outline) "));
|
||||
SERIAL_OUT.println(testRects(ILI9341_GREEN));
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Rectangles (filled) "));
|
||||
SERIAL_OUT.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Circles (filled) "));
|
||||
SERIAL_OUT.println(testFilledCircles(10, ILI9341_MAGENTA));
|
||||
|
||||
SERIAL_OUT.print(F("Circles (outline) "));
|
||||
SERIAL_OUT.println(testCircles(10, ILI9341_WHITE));
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Triangles (outline) "));
|
||||
SERIAL_OUT.println(testTriangles());
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Triangles (filled) "));
|
||||
SERIAL_OUT.println(testFilledTriangles());
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Rounded rects (outline) "));
|
||||
SERIAL_OUT.println(testRoundRects());
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.print(F("Rounded rects (filled) "));
|
||||
SERIAL_OUT.println(testFilledRoundRects());
|
||||
delay(500);
|
||||
|
||||
SERIAL_OUT.println(F("Done!"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop(void) {
|
||||
for(uint8_t rotation=0; rotation<4; rotation++) {
|
||||
tft.setRotation(rotation);
|
||||
testText();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
125
libraries/Adafruit_ILI9341/examples/onoffbutton/onoffbutton.ino
Normal file
125
libraries/Adafruit_ILI9341/examples/onoffbutton/onoffbutton.ino
Normal file
@ -0,0 +1,125 @@
|
||||
//This example implements a simple sliding On/Off button. The example
|
||||
// demonstrates drawing and touch operations.
|
||||
//
|
||||
//Thanks to Adafruit forums member Asteroid for the original sketch!
|
||||
//
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ILI9341.h>
|
||||
#include <Adafruit_STMPE610.h>
|
||||
|
||||
// This is calibration data for the raw touch data to the screen coordinates
|
||||
#define TS_MINX 150
|
||||
#define TS_MINY 130
|
||||
#define TS_MAXX 3800
|
||||
#define TS_MAXY 4000
|
||||
|
||||
#define STMPE_CS 8
|
||||
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
||||
#define TFT_CS 10
|
||||
#define TFT_DC 9
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
boolean RecordOn = false;
|
||||
|
||||
#define FRAME_X 210
|
||||
#define FRAME_Y 180
|
||||
#define FRAME_W 100
|
||||
#define FRAME_H 50
|
||||
|
||||
#define REDBUTTON_X FRAME_X
|
||||
#define REDBUTTON_Y FRAME_Y
|
||||
#define REDBUTTON_W (FRAME_W/2)
|
||||
#define REDBUTTON_H FRAME_H
|
||||
|
||||
#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
|
||||
#define GREENBUTTON_Y FRAME_Y
|
||||
#define GREENBUTTON_W (FRAME_W/2)
|
||||
#define GREENBUTTON_H FRAME_H
|
||||
|
||||
void drawFrame()
|
||||
{
|
||||
tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
|
||||
}
|
||||
|
||||
void redBtn()
|
||||
{
|
||||
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
|
||||
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
|
||||
drawFrame();
|
||||
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setTextSize(2);
|
||||
tft.println("ON");
|
||||
RecordOn = false;
|
||||
}
|
||||
|
||||
void greenBtn()
|
||||
{
|
||||
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN);
|
||||
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
|
||||
drawFrame();
|
||||
tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setTextSize(2);
|
||||
tft.println("OFF");
|
||||
RecordOn = true;
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
tft.begin();
|
||||
if (!ts.begin()) {
|
||||
Serial.println("Unable to start touchscreen.");
|
||||
}
|
||||
else {
|
||||
Serial.println("Touchscreen started.");
|
||||
}
|
||||
|
||||
tft.fillScreen(ILI9341_BLUE);
|
||||
// origin = left,top landscape (USB left upper)
|
||||
tft.setRotation(1);
|
||||
redBtn();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// See if there's any touch data for us
|
||||
if (!ts.bufferEmpty())
|
||||
{
|
||||
// Retrieve a point
|
||||
TS_Point p = ts.getPoint();
|
||||
// Scale using the calibration #'s
|
||||
// and rotate coordinate system
|
||||
p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
|
||||
p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
|
||||
int y = tft.height() - p.x;
|
||||
int x = p.y;
|
||||
|
||||
if (RecordOn)
|
||||
{
|
||||
if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
|
||||
if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
|
||||
Serial.println("Red btn hit");
|
||||
redBtn();
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Record is off (RecordOn == false)
|
||||
{
|
||||
if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
|
||||
if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
|
||||
Serial.println("Green btn hit");
|
||||
greenBtn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println(RecordOn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,133 @@
|
||||
//This example implements a simple sliding On/Off button. The example
|
||||
// demonstrates drawing and touch operations.
|
||||
//
|
||||
//Thanks to Adafruit forums member Asteroid for the original sketch!
|
||||
//
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ILI9341.h>
|
||||
#include <TouchScreen.h>
|
||||
|
||||
//Touchscreen X+ X- Y+ Y- pins
|
||||
#define YP A3 // must be an analog pin, use "An" notation!
|
||||
#define XM A2 // must be an analog pin, use "An" notation!
|
||||
#define YM 5 // can be a digital pin
|
||||
#define XP 4 // can be a digital pin
|
||||
|
||||
// This is calibration data for the raw touch data to the screen coordinates
|
||||
#define TS_MINX 150
|
||||
#define TS_MINY 120
|
||||
#define TS_MAXX 920
|
||||
#define TS_MAXY 940
|
||||
|
||||
#define MINPRESSURE 10
|
||||
#define MAXPRESSURE 1000
|
||||
|
||||
// For better pressure precision, we need to know the resistance
|
||||
// between X+ and X- Use any multimeter to read it
|
||||
// For the one we're using, its 300 ohms across the X plate
|
||||
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
|
||||
|
||||
|
||||
#define TFT_CS 10
|
||||
#define TFT_DC 9
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
boolean RecordOn = false;
|
||||
|
||||
#define FRAME_X 210
|
||||
#define FRAME_Y 180
|
||||
#define FRAME_W 100
|
||||
#define FRAME_H 50
|
||||
|
||||
#define REDBUTTON_X FRAME_X
|
||||
#define REDBUTTON_Y FRAME_Y
|
||||
#define REDBUTTON_W (FRAME_W/2)
|
||||
#define REDBUTTON_H FRAME_H
|
||||
|
||||
#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
|
||||
#define GREENBUTTON_Y FRAME_Y
|
||||
#define GREENBUTTON_W (FRAME_W/2)
|
||||
#define GREENBUTTON_H FRAME_H
|
||||
|
||||
void drawFrame()
|
||||
{
|
||||
tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
|
||||
}
|
||||
|
||||
void redBtn()
|
||||
{
|
||||
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
|
||||
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
|
||||
drawFrame();
|
||||
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setTextSize(2);
|
||||
tft.println("ON");
|
||||
RecordOn = false;
|
||||
}
|
||||
|
||||
void greenBtn()
|
||||
{
|
||||
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN);
|
||||
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
|
||||
drawFrame();
|
||||
tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
|
||||
tft.setTextColor(ILI9341_WHITE);
|
||||
tft.setTextSize(2);
|
||||
tft.println("OFF");
|
||||
RecordOn = true;
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
tft.begin();
|
||||
|
||||
tft.fillScreen(ILI9341_BLUE);
|
||||
// origin = left,top landscape (USB left upper)
|
||||
tft.setRotation(1);
|
||||
redBtn();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Retrieve a point
|
||||
TSPoint p = ts.getPoint();
|
||||
|
||||
// See if there's any touch data for us
|
||||
if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
|
||||
{
|
||||
// Scale using the calibration #'s
|
||||
// and rotate coordinate system
|
||||
p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
|
||||
p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
|
||||
int y = tft.height() - p.x;
|
||||
int x = p.y;
|
||||
|
||||
if (RecordOn)
|
||||
{
|
||||
if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
|
||||
if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
|
||||
Serial.println("Red btn hit");
|
||||
redBtn();
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Record is off (RecordOn == false)
|
||||
{
|
||||
if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
|
||||
if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
|
||||
Serial.println("Green btn hit");
|
||||
greenBtn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println(RecordOn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,189 @@
|
||||
/***************************************************
|
||||
This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield
|
||||
----> http://www.adafruit.com/products/1651
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include "Adafruit_ILI9341.h" // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
|
||||
// TFT display and SD card will share the hardware SPI interface.
|
||||
// Hardware SPI pins are specific to the Arduino board type and
|
||||
// cannot be remapped to alternate pins. For Arduino Uno,
|
||||
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
|
||||
|
||||
#define TFT_DC 9
|
||||
#define TFT_CS 10
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
#define SD_CS 4
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
|
||||
tft.begin();
|
||||
tft.fillScreen(ILI9341_BLUE);
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
if (!SD.begin(SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
}
|
||||
Serial.println("OK!");
|
||||
|
||||
bmpDraw("purple.bmp", 0, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
// This function opens a Windows Bitmap (BMP) file and
|
||||
// displays it at the given coordinates. It's sped up
|
||||
// by reading many pixels worth of data at a time
|
||||
// (rather than pixel by pixel). Increasing the buffer
|
||||
// size takes more of the Arduino's precious RAM but
|
||||
// makes loading a little faster. 20 pixels seems a
|
||||
// good balance.
|
||||
|
||||
#define BUFFPIXEL 20
|
||||
|
||||
void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
||||
|
||||
File bmpFile;
|
||||
int bmpWidth, bmpHeight; // W+H in pixels
|
||||
uint8_t bmpDepth; // Bit depth (currently must be 24)
|
||||
uint32_t bmpImageoffset; // Start of image data in file
|
||||
uint32_t rowSize; // Not always = bmpWidth; may have padding
|
||||
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
|
||||
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
|
||||
boolean goodBmp = false; // Set to true on valid header parse
|
||||
boolean flip = true; // BMP is stored bottom-to-top
|
||||
int w, h, row, col;
|
||||
uint8_t r, g, b;
|
||||
uint32_t pos = 0, startTime = millis();
|
||||
|
||||
if((x >= tft.width()) || (y >= tft.height())) return;
|
||||
|
||||
Serial.println();
|
||||
Serial.print(F("Loading image '"));
|
||||
Serial.print(filename);
|
||||
Serial.println('\'');
|
||||
|
||||
// Open requested file on SD card
|
||||
if ((bmpFile = SD.open(filename)) == NULL) {
|
||||
Serial.print(F("File not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse BMP header
|
||||
if(read16(bmpFile) == 0x4D42) { // BMP signature
|
||||
Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
|
||||
(void)read32(bmpFile); // Read & ignore creator bytes
|
||||
bmpImageoffset = read32(bmpFile); // Start of image data
|
||||
Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
|
||||
// Read DIB header
|
||||
Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
|
||||
bmpWidth = read32(bmpFile);
|
||||
bmpHeight = read32(bmpFile);
|
||||
if(read16(bmpFile) == 1) { // # planes -- must be '1'
|
||||
bmpDepth = read16(bmpFile); // bits per pixel
|
||||
Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
|
||||
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
|
||||
|
||||
goodBmp = true; // Supported BMP format -- proceed!
|
||||
Serial.print(F("Image size: "));
|
||||
Serial.print(bmpWidth);
|
||||
Serial.print('x');
|
||||
Serial.println(bmpHeight);
|
||||
|
||||
// BMP rows are padded (if needed) to 4-byte boundary
|
||||
rowSize = (bmpWidth * 3 + 3) & ~3;
|
||||
|
||||
// If bmpHeight is negative, image is in top-down order.
|
||||
// This is not canon but has been observed in the wild.
|
||||
if(bmpHeight < 0) {
|
||||
bmpHeight = -bmpHeight;
|
||||
flip = false;
|
||||
}
|
||||
|
||||
// Crop area to be loaded
|
||||
w = bmpWidth;
|
||||
h = bmpHeight;
|
||||
if((x+w-1) >= tft.width()) w = tft.width() - x;
|
||||
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
||||
|
||||
// Set TFT address window to clipped image bounds
|
||||
tft.setAddrWindow(x, y, x+w-1, y+h-1);
|
||||
|
||||
for (row=0; row<h; row++) { // For each scanline...
|
||||
|
||||
// Seek to start of scan line. It might seem labor-
|
||||
// intensive to be doing this on every line, but this
|
||||
// method covers a lot of gritty details like cropping
|
||||
// and scanline padding. Also, the seek only takes
|
||||
// place if the file position actually needs to change
|
||||
// (avoids a lot of cluster math in SD library).
|
||||
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
|
||||
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
|
||||
else // Bitmap is stored top-to-bottom
|
||||
pos = bmpImageoffset + row * rowSize;
|
||||
if(bmpFile.position() != pos) { // Need seek?
|
||||
bmpFile.seek(pos);
|
||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||
}
|
||||
|
||||
for (col=0; col<w; col++) { // For each pixel...
|
||||
// Time to read more pixel data?
|
||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||
buffidx = 0; // Set index to beginning
|
||||
}
|
||||
|
||||
// Convert pixel from BMP to TFT format, push to display
|
||||
b = sdbuffer[buffidx++];
|
||||
g = sdbuffer[buffidx++];
|
||||
r = sdbuffer[buffidx++];
|
||||
tft.pushColor(tft.color565(r,g,b));
|
||||
} // end pixel
|
||||
} // end scanline
|
||||
Serial.print(F("Loaded in "));
|
||||
Serial.print(millis() - startTime);
|
||||
Serial.println(" ms");
|
||||
} // end goodBmp
|
||||
}
|
||||
}
|
||||
|
||||
bmpFile.close();
|
||||
if(!goodBmp) Serial.println(F("BMP format not recognized."));
|
||||
}
|
||||
|
||||
// These read 16- and 32-bit types from the SD card file.
|
||||
// BMP data is stored little-endian, Arduino is little-endian too.
|
||||
// May need to reverse subscript order if porting elsewhere.
|
||||
|
||||
uint16_t read16(File &f) {
|
||||
uint16_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t read32(File &f) {
|
||||
uint32_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read();
|
||||
((uint8_t *)&result)[2] = f.read();
|
||||
((uint8_t *)&result)[3] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
146
libraries/Adafruit_ILI9341/examples/touchpaint/touchpaint.ino
Normal file
146
libraries/Adafruit_ILI9341/examples/touchpaint/touchpaint.ino
Normal file
@ -0,0 +1,146 @@
|
||||
/***************************************************
|
||||
This is our touchscreen painting example for the Adafruit ILI9341 Shield
|
||||
----> http://www.adafruit.com/products/1651
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <SPI.h>
|
||||
#include <Wire.h> // this is needed even tho we aren't using it
|
||||
#include <Adafruit_ILI9341.h>
|
||||
#include <Adafruit_STMPE610.h>
|
||||
|
||||
// This is calibration data for the raw touch data to the screen coordinates
|
||||
#define TS_MINX 150
|
||||
#define TS_MINY 130
|
||||
#define TS_MAXX 3800
|
||||
#define TS_MAXY 4000
|
||||
|
||||
// The STMPE610 uses hardware SPI on the shield, and #8
|
||||
#define STMPE_CS 8
|
||||
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
|
||||
|
||||
// The display also uses hardware SPI, plus #9 & #10
|
||||
#define TFT_CS 10
|
||||
#define TFT_DC 9
|
||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
|
||||
|
||||
// Size of the color selection boxes and the paintbrush size
|
||||
#define BOXSIZE 40
|
||||
#define PENRADIUS 3
|
||||
int oldcolor, currentcolor;
|
||||
|
||||
void setup(void) {
|
||||
// while (!Serial); // used for leonardo debugging
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("Touch Paint!"));
|
||||
|
||||
tft.begin();
|
||||
|
||||
if (!ts.begin()) {
|
||||
Serial.println("Couldn't start touchscreen controller");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("Touchscreen started");
|
||||
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
|
||||
// make the color selection boxes
|
||||
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
|
||||
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
|
||||
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
|
||||
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
|
||||
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
|
||||
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
|
||||
|
||||
// select the current color 'red'
|
||||
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
currentcolor = ILI9341_RED;
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// See if there's any touch data for us
|
||||
if (ts.bufferEmpty()) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// You can also wait for a touch
|
||||
if (! ts.touched()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// Retrieve a point
|
||||
TS_Point p = ts.getPoint();
|
||||
|
||||
/*
|
||||
Serial.print("X = "); Serial.print(p.x);
|
||||
Serial.print("\tY = "); Serial.print(p.y);
|
||||
Serial.print("\tPressure = "); Serial.println(p.z);
|
||||
*/
|
||||
|
||||
// Scale from ~0->4000 to tft.width using the calibration #'s
|
||||
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
|
||||
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
|
||||
|
||||
/*
|
||||
Serial.print("("); Serial.print(p.x);
|
||||
Serial.print(", "); Serial.print(p.y);
|
||||
Serial.println(")");
|
||||
*/
|
||||
|
||||
if (p.y < BOXSIZE) {
|
||||
oldcolor = currentcolor;
|
||||
|
||||
if (p.x < BOXSIZE) {
|
||||
currentcolor = ILI9341_RED;
|
||||
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*2) {
|
||||
currentcolor = ILI9341_YELLOW;
|
||||
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*3) {
|
||||
currentcolor = ILI9341_GREEN;
|
||||
tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*4) {
|
||||
currentcolor = ILI9341_CYAN;
|
||||
tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*5) {
|
||||
currentcolor = ILI9341_BLUE;
|
||||
tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
} else if (p.x < BOXSIZE*6) {
|
||||
currentcolor = ILI9341_MAGENTA;
|
||||
tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
|
||||
}
|
||||
|
||||
if (oldcolor != currentcolor) {
|
||||
if (oldcolor == ILI9341_RED)
|
||||
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
|
||||
if (oldcolor == ILI9341_YELLOW)
|
||||
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
|
||||
if (oldcolor == ILI9341_GREEN)
|
||||
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
|
||||
if (oldcolor == ILI9341_CYAN)
|
||||
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
|
||||
if (oldcolor == ILI9341_BLUE)
|
||||
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
|
||||
if (oldcolor == ILI9341_MAGENTA)
|
||||
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
|
||||
}
|
||||
}
|
||||
if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
|
||||
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user