fixings, cleaning, new examples

This commit is contained in:
sumotoy 2015-03-01 00:03:23 +01:00
parent d39a98aedc
commit b0a363bf62
13 changed files with 328 additions and 275 deletions

View file

@ -375,37 +375,36 @@ void TFT_ILI9163C::colorSpace(uint8_t cspace) {
void TFT_ILI9163C::clearScreen(uint16_t color) { void TFT_ILI9163C::clearScreen(uint16_t color) {
int px;
setAddr(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1);
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); for (px = 0;px < _GRAMSIZE-1; px++){
_setAddrWindow(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1);
for (int px = 0;px < _GRAMSIZE-1; px++){
writedata16_cont(color); writedata16_cont(color);
} }
writedata16_last(color); writedata16_last(color);
SPI.endTransaction(); endProc();
#else #else
homeAddress(); for (px = 0;px < _GRAMSIZE; px++){
for (int px = 0;px < _GRAMSIZE; px++){ writedata16(color);
writedata16(color); }
}
#endif #endif
} }
void TFT_ILI9163C::writeScreen(const uint32_t *bitmap) { void TFT_ILI9163C::writeScreen(const uint32_t *bitmap) {
uint16_t color; uint16_t color;
int px;
setAddr(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1);
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); for (px = 0;px < 16383; px++){
_setAddrWindow(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1);
for (uint32_t px = 0;px < 16383; px++){
color = Color24To565(bitmap[px]); color = Color24To565(bitmap[px]);
writedata16_cont(color); writedata16_cont(color);
} }
color = Color24To565(bitmap[16383]); color = Color24To565(bitmap[16383]);
writedata16_last(color); writedata16_last(color);
SPI.endTransaction(); endProc();
#else #else
homeAddress(); for (px = 0;px < 16384; px++){
for (uint32_t px = 0;px < 16384; px++){
color = Color24To565(bitmap[px]); color = Color24To565(bitmap[px]);
writedata16(color); writedata16(color);
} }
@ -440,18 +439,30 @@ void TFT_ILI9163C::pushColor(uint16_t color) {
void TFT_ILI9163C::drawPixel(int16_t x, int16_t y, uint16_t color) { void TFT_ILI9163C::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (boundaryCheck(x,y)) return; if (boundaryCheck(x,y)) return;
if ((x < 0) || (y < 0)) return; if ((x < 0) || (y < 0)) return;
setAddr(x,y,x+1,y+1);
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x,y,x+1,y+1);
//setAddr(x, y, x, y);//
//writecommand_cont(CMD_RAMWR);//not needed //writecommand_cont(CMD_RAMWR);//not needed
writedata16_last(color); writedata16_last(color);
SPI.endTransaction(); endProc();
#else #else
setAddrWindow(x,y,x+1,y+1);
writedata16(color); writedata16(color);
#endif #endif
}
void TFT_ILI9163C::setAddr(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1){
#if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x0,y0,x1,y1);
#else
setAddrWindow(x0,y0,x1,y1);
#endif
}
void TFT_ILI9163C::endProc(void){
#if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.endTransaction();
#endif
} }
@ -459,13 +470,7 @@ void TFT_ILI9163C::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color
// Rudimentary clipping // Rudimentary clipping
if (boundaryCheck(x,y)) return; if (boundaryCheck(x,y)) return;
if (((y + h) - 1) >= _height) h = _height-y; if (((y + h) - 1) >= _height) h = _height-y;
setAddr(x,y,x,(y+h)-1);
#if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x,y,x,(y+h)-1);
#else
setAddrWindow(x,y,x,(y+h)-1);
#endif
while (h-- > 1) { while (h-- > 1) {
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
if (h == 0){ if (h == 0){
@ -477,9 +482,7 @@ void TFT_ILI9163C::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color
writedata16(color); writedata16(color);
#endif #endif
} }
#if defined(__MK20DX128__) || defined(__MK20DX256__) endProc();
SPI.endTransaction();
#endif
} }
bool TFT_ILI9163C::boundaryCheck(int16_t x,int16_t y){ bool TFT_ILI9163C::boundaryCheck(int16_t x,int16_t y){
@ -491,12 +494,7 @@ void TFT_ILI9163C::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color
// Rudimentary clipping // Rudimentary clipping
if (boundaryCheck(x,y)) return; if (boundaryCheck(x,y)) return;
if (((x+w) - 1) >= _width) w = _width-x; if (((x+w) - 1) >= _width) w = _width-x;
#if defined(__MK20DX128__) || defined(__MK20DX256__) setAddr(x,y,(x+w)-1,y);
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x,y,(x+w)-1,y);
#else
setAddrWindow(x,y,(x+w)-1,y);
#endif
while (w-- > 1) { while (w-- > 1) {
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
if (w == 0){ if (w == 0){
@ -508,9 +506,7 @@ void TFT_ILI9163C::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color
writedata16(color); writedata16(color);
#endif #endif
} }
#if defined(__MK20DX128__) || defined(__MK20DX256__) endProc();
SPI.endTransaction();
#endif
} }
void TFT_ILI9163C::fillScreen(uint16_t color) { void TFT_ILI9163C::fillScreen(uint16_t color) {
@ -522,12 +518,7 @@ void TFT_ILI9163C::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t
if (boundaryCheck(x,y)) return; if (boundaryCheck(x,y)) return;
if (((x + w) - 1) >= _width) w = _width - x; if (((x + w) - 1) >= _width) w = _width - x;
if (((y + h) - 1) >= _height) h = _height - y; if (((y + h) - 1) >= _height) h = _height - y;
#if defined(__MK20DX128__) || defined(__MK20DX256__) setAddr(x,y,(x+w)-1,(y+h)-1);
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x,y,(x+w)-1,(y+h)-1);
#else
setAddrWindow(x,y,(x+w)-1,(y+h)-1);
#endif
for (y = h;y > 0;y--) { for (y = h;y > 0;y--) {
for (x = w;x > 1;x--) { for (x = w;x > 1;x--) {
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
@ -540,9 +531,7 @@ void TFT_ILI9163C::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t
writedata16_last(color); writedata16_last(color);
#endif #endif
} }
#if defined(__MK20DX128__) || defined(__MK20DX256__) endProc();
SPI.endTransaction();
#endif
} }
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
@ -654,40 +643,9 @@ uint16_t TFT_ILI9163C::Color565(uint8_t r, uint8_t g, uint8_t b) {
void TFT_ILI9163C::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { void TFT_ILI9163C::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
writecommand_cont(CMD_CLMADRS); // Column _setAddrWindow(x0,y0,x1,y1);
if (rotation == 0){
writedata16_cont(x0);
writedata16_cont(x1);
} else if (rotation == 1){
writedata16_cont(x0 + __OFFSET);
writedata16_cont(x1 + __OFFSET);
} else if (rotation == 2){
writedata16_cont(x0);
writedata16_cont(x1);
} else {
writedata16_cont(x0);
writedata16_cont(x1);
}
writecommand_cont(CMD_PGEADRS); // Page
if (rotation == 0){
writedata16_cont(y0 + __OFFSET);
writedata16_cont(y1 + __OFFSET);
} else if (rotation == 1){
writedata16_cont(y0);
writedata16_cont(y1);
} else if (rotation == 2){
writedata16_cont(y0);
writedata16_cont(y1);
} else {
writedata16_cont(y0);
writedata16_cont(y1);
}
writecommand_last(CMD_RAMWR); //Into RAM
SPI.endTransaction(); SPI.endTransaction();
#else #else
writecommand(CMD_CLMADRS); // Column writecommand(CMD_CLMADRS); // Column
if (rotation == 0){ if (rotation == 0){
@ -754,7 +712,6 @@ void TFT_ILI9163C::_setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_
writedata16_cont(y1); writedata16_cont(y1);
} }
writecommand_cont(CMD_RAMWR); //Into RAM writecommand_cont(CMD_RAMWR); //Into RAM
} }
#endif #endif
@ -805,142 +762,3 @@ void TFT_ILI9163C::invertDisplay(boolean i) {
#endif #endif
} }
/*
// Draw a character
void TFT_ILI9163C::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t fgcolor, uint16_t bgcolor, uint8_t size){
if((x >= _width) || // Clip right
(y >= _height) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left TODO: is this correct?
((y + 8 * size - 1) < 0)) // Clip top TODO: is this correct?
return;
if (fgcolor == bgcolor) {
// This transparent approach is only about 20% faster
if (size == 1) {
uint8_t mask = 0x01;
int16_t xoff, yoff;
for (yoff=0; yoff < 8; yoff++) {
uint8_t line = 0;
for (xoff=0; xoff < 5; xoff++) {
if (font[c * 5 + xoff] & mask) line |= 1;
line <<= 1;
}
line >>= 1;
xoff = 0;
while (line) {
if (line == 0x1F) {
drawFastHLine(x + xoff, y + yoff, 5, fgcolor);
break;
} else if (line == 0x1E) {
drawFastHLine(x + xoff, y + yoff, 4, fgcolor);
break;
} else if ((line & 0x1C) == 0x1C) {
drawFastHLine(x + xoff, y + yoff, 3, fgcolor);
line <<= 4;
xoff += 4;
} else if ((line & 0x18) == 0x18) {
drawFastHLine(x + xoff, y + yoff, 2, fgcolor);
line <<= 3;
xoff += 3;
} else if ((line & 0x10) == 0x10) {
drawPixel(x + xoff, y + yoff, fgcolor);
line <<= 2;
xoff += 2;
} else {
line <<= 1;
xoff += 1;
}
}
mask = mask << 1;
}
} else {
uint8_t mask = 0x01;
int16_t xoff, yoff;
for (yoff=0; yoff < 8; yoff++) {
uint8_t line = 0;
for (xoff=0; xoff < 5; xoff++) {
if (font[c * 5 + xoff] & mask) line |= 1;
line <<= 1;
}
line >>= 1;
xoff = 0;
while (line) {
if (line == 0x1F) {
fillRect(x + xoff * size, y + yoff * size,
5 * size, size, fgcolor);
break;
} else if (line == 0x1E) {
fillRect(x + xoff * size, y + yoff * size,
4 * size, size, fgcolor);
break;
} else if ((line & 0x1C) == 0x1C) {
fillRect(x + xoff * size, y + yoff * size,
3 * size, size, fgcolor);
line <<= 4;
xoff += 4;
} else if ((line & 0x18) == 0x18) {
fillRect(x + xoff * size, y + yoff * size,
2 * size, size, fgcolor);
line <<= 3;
xoff += 3;
} else if ((line & 0x10) == 0x10) {
fillRect(x + xoff * size, y + yoff * size,
size, size, fgcolor);
line <<= 2;
xoff += 2;
} else {
line <<= 1;
xoff += 1;
}
}
mask = mask << 1;
}
}
} else {
// This solid background approach is about 5 time faster
#if defined(__MK20DX128__) || defined(__MK20DX256__)
SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0));
_setAddrWindow(x, y, x + 6 * size - 1, y + 8 * size - 1);
//writecommand_cont(ILI9341_RAMWR);
#else
setAddrWindow(x, y, x + 6 * size - 1, y + 8 * size - 1);
#endif
uint8_t xr, yr;
uint8_t mask = 0x01;
uint16_t color;
for (y=0; y < 8; y++) {
for (yr=0; yr < size; yr++) {
for (x=0; x < 5; x++) {
if (font[c * 5 + x] & mask) {
color = fgcolor;
} else {
color = bgcolor;
}
for (xr=0; xr < size; xr++) {
#if defined(__MK20DX128__) || defined(__MK20DX256__)
writedata16_cont(color);
#else
writedata16(color);
#endif
}
}
for (xr=0; xr < size; xr++) {
#if defined(__MK20DX128__) || defined(__MK20DX256__)
writedata16_cont(bgcolor);
#else
writedata16(bgcolor);
#endif
}
}
mask = mask << 1;
}
#if defined(__MK20DX128__) || defined(__MK20DX256__)
writecommand_last(CMD_NOP);
SPI.endTransaction();
#else
writecommand(CMD_NOP);
#endif
}
}
*/

View file

@ -71,6 +71,7 @@
0.3b1: Complete rework on Teensy SPI based on Paul Stoffregen work 0.3b1: Complete rework on Teensy SPI based on Paul Stoffregen work
SPI transaction,added BLACK TAG 2.2 display SPI transaction,added BLACK TAG 2.2 display
0.3b2: Minor fix, load 24bit image, Added conversion utility 0.3b2: Minor fix, load 24bit image, Added conversion utility
0.4:some improvement, new ballistic gauge example!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BugList of the current version: BugList of the current version:
@ -236,6 +237,7 @@ Not tested!
#define CMD_GAMRSEL 0xF2//GAM_R_SEL #define CMD_GAMRSEL 0xF2//GAM_R_SEL
class TFT_ILI9163C : public Adafruit_GFX { class TFT_ILI9163C : public Adafruit_GFX {
public: public:
@ -269,6 +271,8 @@ class TFT_ILI9163C : public Adafruit_GFX {
uint8_t _Mactrl_Data;//container for the memory access control data uint8_t _Mactrl_Data;//container for the memory access control data
uint8_t _colorspaceData; uint8_t _colorspaceData;
void colorSpace(uint8_t cspace); void colorSpace(uint8_t cspace);
void setAddr(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void endProc(void);
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(__MK20DX128__) || defined(__MK20DX256__)
// //
#else #else
@ -381,6 +385,4 @@ class TFT_ILI9163C : public Adafruit_GFX {
#endif #endif
}; };
#endif #endif

View file

@ -5,7 +5,25 @@
//be careful, big image! Only Teensy or DUE probably work //be careful, big image! Only Teensy or DUE probably work
TFT_ILI9163C tft = TFT_ILI9163C(10, 9); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
static const uint32_t image_data_batman_ume[16384] = { static const uint32_t image_data_batman_ume[16384] = {
@ -13,13 +31,11 @@ static const uint32_t image_data_batman_ume[16384] = {
}; };
void setup() { void setup() {
Serial.begin(9600);
tft.begin(); tft.begin();
tft.writeScreen(image_data_batman_ume); tft.writeScreen(image_data_batman_ume);
} }
void loop(void) { void loop(void) {
delay(1);
} }

View file

@ -3,35 +3,30 @@
#include <TFT_ILI9163C.h> #include <TFT_ILI9163C.h>
/* /*
Note for Teensy 3.x !!!!!!!!!!!!!!!!!!! Teensy3.x and Arduino's
You should choose from those pins for CS and RS: You are using 4 wire SPI here, so:
2,6,9,10,15,20,23 MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/ */
#define __CS 10 #define __CS 10
#define __DC 9 #define __DC 9
#define __RST 14 /*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC);
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TRANSPARENT -1
TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC, __RST);
float p = 3.1415926; float p = 3.1415926;
void setup(void) { void setup(void) {
display.begin(); display.begin();
display.setBitrate(24000000);
uint16_t time = millis(); uint16_t time = millis();
time = millis() - time; time = millis() - time;

View file

@ -12,13 +12,21 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10 #define __CS 10
#define __DC 9 #define __DC 9
/* /*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23 Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any Arduino's 8 bit: any
DUE: check site DUE: check arduino site
If you do not use reset, tie it to +3V3
*/ */

View file

@ -2,9 +2,6 @@
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h> #include <TFT_ILI9163C.h>
#define __CS 10
#define __DC 9
#define __RST 14
// Color definitions // Color definitions
#define BLACK 0x0000 #define BLACK 0x0000
@ -16,17 +13,17 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
float sin_d[] = { const float sin_d[] = {
0,0.17,0.34,0.5,0.64,0.77,0.87,0.94,0.98,1,0.98,0.94, 0,0.17,0.34,0.5,0.64,0.77,0.87,0.94,0.98,1,0.98,0.94,
0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,-0.5,-0.64, 0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,-0.5,-0.64,
-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,-0.77, -0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,-0.77,
-0.64,-0.5,-0.34,-0.17 }; -0.64,-0.5,-0.34,-0.17 };
float cos_d[] = { const float cos_d[] = {
1,0.98,0.94,0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34, 1,0.98,0.94,0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,
-0.5,-0.64,-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87, -0.5,-0.64,-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,
-0.77,-0.64,-0.5,-0.34,-0.17,0,0.17,0.34,0.5,0.64,0.77, -0.77,-0.64,-0.5,-0.34,-0.17,0,0.17,0.34,0.5,0.64,0.77,
0.87,0.94,0.98}; 0.87,0.94,0.98};
float d = 10; const float d = 10;
float px[] = { float px[] = {
-d, d, d, -d, -d, d, d, -d }; -d, d, d, -d, -d, d, d, -d };
float py[] = { float py[] = {
@ -42,14 +39,28 @@ float p2y[] = {
int r[] = { int r[] = {
0,0,0}; 0,0,0};
/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, __RST);
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup() { void setup() {
tft.begin(); tft.begin();
#if defined(__MK20DX128__) || defined(__MK20DX256__)
tft.setBitrate(24000000);
#endif
} }
void loop(){ void loop(){

View file

@ -8,9 +8,6 @@
#define F(string_literal) string_literal #define F(string_literal) string_literal
#endif #endif
#define __CS 10
#define __DC 9
#define __RST 14
// Color definitions // Color definitions
#define BLACK 0x0000 #define BLACK 0x0000
@ -22,15 +19,30 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, __RST); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
//while (!Serial); //while (!Serial);
tft.begin(); tft.begin();
#if defined(__MK20DX128__) || defined(__MK20DX256__)
tft.setBitrate(24000000);
#endif
Serial.println(F("Benchmark Time (microseconds)")); Serial.println(F("Benchmark Time (microseconds)"));
Serial.print(F("Screen fill ")); Serial.print(F("Screen fill "));

View file

@ -12,9 +12,28 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
TFT_ILI9163C tft = TFT_ILI9163C(10, 9, 14); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup() { void setup() {
tft.begin();
} }
void loop(void) { void loop(void) {

View file

@ -26,6 +26,7 @@ You are using 4 wire SPI here, so:
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23 Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any Arduino's 8 bit: any
DUE: check arduino site DUE: check arduino site
If you do not use reset, tie it to +3V3
*/ */

View file

@ -0,0 +1,120 @@
/*
ROUND GAUGE EXAMPLE with ballistic!
This example show how to create a round gauge that react like the real one with (almost) correct ballistic
Created by S.U.M.O.T.O.Y - Max MC Costa
If you modify or get better result please let me know
*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
volatile int16_t curVal1 = 0;
volatile int16_t oldVal1 = 0;
/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup() {
Serial.begin(9600);
tft.begin();
drawGauge(63,63,63);
}
void loop(void) {
curVal1 = random(1,254);
if (oldVal1 != curVal1){
drawNeedle(curVal1,63,63,63,GREEN,BLACK);
oldVal1 = curVal1;
}
}
void drawGauge(uint8_t x,uint8_t y,uint8_t r) {
tft.drawCircle(x, y, r,WHITE);//draw instrument container
faceHelper(x,y,r,150,390,1.3);//draw major ticks
if (r > 15) faceHelper(x,y,r,165,375,1.1);//draw minor ticks
}
void faceHelper(uint8_t x,uint8_t y,uint8_t r,int from,int to,float dev){
float dsec,fromSecX,fromSecY,toSecX,toSecY;
int i;
for (i = from;i <= to;i += 30) {
dsec = i * (PI / 180);
fromSecX = cos(dsec) * (r / dev);
fromSecY = sin(dsec) * (r / dev);
toSecX = cos(dsec) * r;
toSecY = sin(dsec) * r;
tft.drawLine(1 + x + fromSecX,1 + y + fromSecY,1 + x + toSecX,1 + y + toSecY,WHITE);
}
}
void drawNeedle(int16_t val,uint8_t x,uint8_t y,uint8_t r,uint16_t color,uint16_t bcolor){
uint8_t i;
if (curVal1 > oldVal1){
for (i = oldVal1; i <= curVal1; i++){
drawPointerHelper(i-1,63,63,63,bcolor);
drawPointerHelper(i,63,63,63,color);
if ((curVal1 - oldVal1) < (128)) delay(1);//ballistic
}
}
else {
for (i = oldVal1; i >= curVal1; i--){
drawPointerHelper(i+1,63,63,63,bcolor);
drawPointerHelper(i,63,63,63,color);
//ballistic
if ((oldVal1 - curVal1) >= 128){
delay(1);
} else {
delay(3);
}
}
}
}
void drawPointerHelper(int16_t val,uint8_t x,uint8_t y,uint8_t r,uint16_t color) {
float dsec, toSecX, toSecY;
int16_t minValue = 0;
int16_t maxValue = 255;
int fromDegree = 150;//start
int toDegree = 240;//end
if (val > maxValue) val = maxValue;
if (val < minValue) val = minValue;
dsec = (((float)(uint16_t)(val - minValue) / (float)(uint16_t)(maxValue - minValue) * toDegree) + fromDegree) * (PI / 180);
toSecX = cos(dsec) * (r / 1.35);
toSecY = sin(dsec) * (r / 1.35);
tft.drawLine(x, y, 1 + x + toSecX, 1 + y + toSecY, color);
tft.fillCircle(x,y,2,color);
}

View file

@ -20,7 +20,25 @@ uint16_t t_b[NBINS];
uint16_t datax_[NBINS]; uint16_t datax_[NBINS];
TFT_ILI9163C tft = TFT_ILI9163C(10, 9); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup(void) { void setup(void) {
Serial.begin(38400); Serial.begin(38400);

View file

@ -2,9 +2,6 @@
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h> #include <TFT_ILI9163C.h>
#define __CS 10
#define __DC 9
#define __RST 14
// Color definitions // Color definitions
#define BLACK 0x0000 #define BLACK 0x0000
@ -16,7 +13,25 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, __RST); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup() { void setup() {
tft.begin(); tft.begin();

View file

@ -15,12 +15,30 @@
#define YELLOW 0xFFE0 #define YELLOW 0xFFE0
#define WHITE 0xFFFF #define WHITE 0xFFFF
#define NBINS 8 #define NBINS 8
const uint8_t bar_Width = 7; const uint8_t bar_Width = 7;
uint32_t avrg_TmrF = 0; uint32_t avrg_TmrF = 0;
uint16_t t_b[NBINS]; uint16_t t_b[NBINS];
TFT_ILI9163C tft = TFT_ILI9163C(10, 9); /*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
the rest of pin below:
*/
#define __CS 10
#define __DC 9
/*
Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
void setup(void) { void setup(void) {