diff --git a/TFT_ILI9163C.cpp b/TFT_ILI9163C.cpp index df9a246..5ae0ef9 100644 --- a/TFT_ILI9163C.cpp +++ b/TFT_ILI9163C.cpp @@ -375,37 +375,36 @@ void TFT_ILI9163C::colorSpace(uint8_t cspace) { void TFT_ILI9163C::clearScreen(uint16_t color) { + int px; + setAddr(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1); #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); - _setAddrWindow(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1); - for (int px = 0;px < _GRAMSIZE-1; px++){ + for (px = 0;px < _GRAMSIZE-1; px++){ writedata16_cont(color); } writedata16_last(color); - SPI.endTransaction(); + endProc(); #else - homeAddress(); - for (int px = 0;px < _GRAMSIZE; px++){ - writedata16(color); - } + for (px = 0;px < _GRAMSIZE; px++){ + writedata16(color); + } #endif + } void TFT_ILI9163C::writeScreen(const uint32_t *bitmap) { uint16_t color; + int px; + setAddr(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1); #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); - _setAddrWindow(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1); - for (uint32_t px = 0;px < 16383; px++){ + for (px = 0;px < 16383; px++){ color = Color24To565(bitmap[px]); writedata16_cont(color); } color = Color24To565(bitmap[16383]); writedata16_last(color); - SPI.endTransaction(); + endProc(); #else - homeAddress(); - for (uint32_t px = 0;px < 16384; px++){ + for (px = 0;px < 16384; px++){ color = Color24To565(bitmap[px]); 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) { if (boundaryCheck(x,y)) return; if ((x < 0) || (y < 0)) return; - + setAddr(x,y,x+1,y+1); #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 writedata16_last(color); - SPI.endTransaction(); + endProc(); #else - setAddrWindow(x,y,x+1,y+1); writedata16(color); #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 if (boundaryCheck(x,y)) return; if (((y + h) - 1) >= _height) h = _height-y; - - #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 + setAddr(x,y,x,(y+h)-1); while (h-- > 1) { #if defined(__MK20DX128__) || defined(__MK20DX256__) 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); #endif } - #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.endTransaction(); - #endif + endProc(); } 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 if (boundaryCheck(x,y)) return; if (((x+w) - 1) >= _width) w = _width-x; - #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); - _setAddrWindow(x,y,(x+w)-1,y); - #else - setAddrWindow(x,y,(x+w)-1,y); - #endif + setAddr(x,y,(x+w)-1,y); while (w-- > 1) { #if defined(__MK20DX128__) || defined(__MK20DX256__) 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); #endif } - #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.endTransaction(); - #endif + endProc(); } 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 (((x + w) - 1) >= _width) w = _width - x; if (((y + h) - 1) >= _height) h = _height - y; - #if defined(__MK20DX128__) || defined(__MK20DX256__) - 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 + setAddr(x,y,(x+w)-1,(y+h)-1); for (y = h;y > 0;y--) { for (x = w;x > 1;x--) { #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); #endif } - #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.endTransaction(); - #endif + endProc(); } #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) { #if defined(__MK20DX128__) || defined(__MK20DX256__) - SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); - writecommand_cont(CMD_CLMADRS); // Column - 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 + _setAddrWindow(x0,y0,x1,y1); SPI.endTransaction(); - #else writecommand(CMD_CLMADRS); // Column if (rotation == 0){ @@ -754,7 +712,6 @@ void TFT_ILI9163C::_setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_ writedata16_cont(y1); } writecommand_cont(CMD_RAMWR); //Into RAM - } #endif @@ -805,142 +762,3 @@ void TFT_ILI9163C::invertDisplay(boolean i) { #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 - } -} -*/ \ No newline at end of file diff --git a/TFT_ILI9163C.h b/TFT_ILI9163C.h index a387a70..5556903 100644 --- a/TFT_ILI9163C.h +++ b/TFT_ILI9163C.h @@ -71,6 +71,7 @@ 0.3b1: Complete rework on Teensy SPI based on Paul Stoffregen work SPI transaction,added BLACK TAG 2.2 display 0.3b2: Minor fix, load 24bit image, Added conversion utility + 0.4:some improvement, new ballistic gauge example! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BugList of the current version: @@ -236,6 +237,7 @@ Not tested! #define CMD_GAMRSEL 0xF2//GAM_R_SEL + class TFT_ILI9163C : public Adafruit_GFX { public: @@ -269,6 +271,8 @@ class TFT_ILI9163C : public Adafruit_GFX { uint8_t _Mactrl_Data;//container for the memory access control data uint8_t _colorspaceData; 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__) // #else @@ -381,6 +385,4 @@ class TFT_ILI9163C : public Adafruit_GFX { #endif }; - - #endif \ No newline at end of file diff --git a/examples/bigPicture/bigPicture.ino b/examples/bigPicture/bigPicture.ino index 5162363..d63ee3e 100644 --- a/examples/bigPicture/bigPicture.ino +++ b/examples/bigPicture/bigPicture.ino @@ -5,7 +5,25 @@ //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] = { @@ -13,13 +31,11 @@ static const uint32_t image_data_batman_ume[16384] = { }; void setup() { - Serial.begin(9600); tft.begin(); tft.writeScreen(image_data_batman_ume); } void loop(void) { - - delay(1); + } \ No newline at end of file diff --git a/examples/bigtest/bigtest.ino b/examples/bigtest/bigtest.ino index cf2e904..d7f6232 100644 --- a/examples/bigtest/bigtest.ino +++ b/examples/bigtest/bigtest.ino @@ -3,35 +3,30 @@ #include /* -Note for Teensy 3.x !!!!!!!!!!!!!!!!!!! - You should choose from those pins for CS and RS: - 2,6,9,10,15,20,23 +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 -#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 +*/ - -// 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); +TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC); float p = 3.1415926; void setup(void) { display.begin(); - display.setBitrate(24000000); + uint16_t time = millis(); time = millis() - time; diff --git a/examples/clock/clock.ino b/examples/clock/clock.ino index 5600bcf..bfa0f4b 100644 --- a/examples/clock/clock.ino +++ b/examples/clock/clock.ino @@ -12,13 +12,21 @@ #define YELLOW 0xFFE0 #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 __DC 9 - /* Teensy 3.x can use: 2,6,9,10,15,20,21,22,23 Arduino's 8 bit: any -DUE: check site +DUE: check arduino site +If you do not use reset, tie it to +3V3 */ diff --git a/examples/cube/cube.ino b/examples/cube/cube.ino index 71e3baf..35de8d6 100644 --- a/examples/cube/cube.ino +++ b/examples/cube/cube.ino @@ -2,9 +2,6 @@ #include #include -#define __CS 10 -#define __DC 9 -#define __RST 14 // Color definitions #define BLACK 0x0000 @@ -16,17 +13,17 @@ #define YELLOW 0xFFE0 #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.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.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, -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.87,0.94,0.98}; -float d = 10; +const float d = 10; float px[] = { -d, d, d, -d, -d, d, d, -d }; float py[] = { @@ -42,14 +39,28 @@ float p2y[] = { int r[] = { 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() { tft.begin(); - #if defined(__MK20DX128__) || defined(__MK20DX256__) - tft.setBitrate(24000000); - #endif } void loop(){ diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino index b72194f..e5332be 100644 --- a/examples/graphicstest/graphicstest.ino +++ b/examples/graphicstest/graphicstest.ino @@ -8,9 +8,6 @@ #define F(string_literal) string_literal #endif -#define __CS 10 -#define __DC 9 -#define __RST 14 // Color definitions #define BLACK 0x0000 @@ -22,15 +19,30 @@ #define YELLOW 0xFFE0 #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() { Serial.begin(9600); //while (!Serial); tft.begin(); - #if defined(__MK20DX128__) || defined(__MK20DX256__) - tft.setBitrate(24000000); - #endif Serial.println(F("Benchmark Time (microseconds)")); Serial.print(F("Screen fill ")); diff --git a/examples/minimal/minimal.ino b/examples/minimal/minimal.ino index 670cfc0..13ddb64 100644 --- a/examples/minimal/minimal.ino +++ b/examples/minimal/minimal.ino @@ -12,9 +12,28 @@ #define YELLOW 0xFFE0 #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() { + tft.begin(); } void loop(void) { diff --git a/examples/mood/mood.ino b/examples/mood/mood.ino index caf10de..9a31d13 100644 --- a/examples/mood/mood.ino +++ b/examples/mood/mood.ino @@ -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 Arduino's 8 bit: any DUE: check arduino site +If you do not use reset, tie it to +3V3 */ diff --git a/examples/roundGaugeWithBallistic/roundGaugeWithBallistic.ino b/examples/roundGaugeWithBallistic/roundGaugeWithBallistic.ino new file mode 100644 index 0000000..8170e73 --- /dev/null +++ b/examples/roundGaugeWithBallistic/roundGaugeWithBallistic.ino @@ -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 +#include +#include + + + +// 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); +} + + diff --git a/examples/simpleBars/simpleBars.ino b/examples/simpleBars/simpleBars.ino index d183f9d..e45677c 100644 --- a/examples/simpleBars/simpleBars.ino +++ b/examples/simpleBars/simpleBars.ino @@ -20,7 +20,25 @@ uint16_t t_b[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) { Serial.begin(38400); diff --git a/examples/test/test.ino b/examples/test/test.ino index be59d43..b03b5be 100644 --- a/examples/test/test.ino +++ b/examples/test/test.ino @@ -2,9 +2,6 @@ #include #include -#define __CS 10 -#define __DC 9 -#define __RST 14 // Color definitions #define BLACK 0x0000 @@ -16,7 +13,25 @@ #define YELLOW 0xFFE0 #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() { tft.begin(); diff --git a/examples/vertical_Gauges/vertical_gauges.ino b/examples/vertical_Gauges/vertical_gauges.ino index fe50bf7..691719e 100644 --- a/examples/vertical_Gauges/vertical_gauges.ino +++ b/examples/vertical_Gauges/vertical_gauges.ino @@ -15,12 +15,30 @@ #define YELLOW 0xFFE0 #define WHITE 0xFFFF -#define NBINS 8 -const uint8_t bar_Width = 7; -uint32_t avrg_TmrF = 0; -uint16_t t_b[NBINS]; +#define NBINS 8 +const uint8_t bar_Width = 7; +uint32_t avrg_TmrF = 0; +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) {