Added adafruit_gfx_as library adapted to maple mini

This commit is contained in:
victorpv 2015-03-12 19:43:03 -05:00
parent 26150944c1
commit 5a3f0db33a
2 changed files with 349 additions and 0 deletions

View File

@ -0,0 +1,124 @@
/*
An example showing rainbow colours on a 2.2" TFT LCD screen
and to show a basic example of font use.
The existing Adafruit font is still in the library
Only new font sizes 2,4,6 and 7 are implemented in the Adafruit_GFX_AS library.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Alan Senior 18/1/2015
*/
// These are the connections for the UNO
#define sclk 13 // Don't change
#define mosi 11 // Don't change
#define cs 9
#define dc 8
#define rst 7 // you can also connect this to the Arduino reset
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_AS.h> // Hardware-specific library
#include <SPI.h>
Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
tft.init();
tft.setRotation(2);
tft.fillScreen(ILI9341_BLACK);
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis()+10000;
for (int i = 0; i<240; i++) {
tft.drawFastVLine(i, 0, tft.height(), colour);
switch (state) {
case 0:
green +=2;
if (green == 64) {
green=63;
state = 1;
}
break;
case 1:
red--;
if (red == 255) {
red = 0;
state = 2;
}
break;
case 2:
blue ++;
if (blue == 32) {
blue=31;
state = 3;
}
break;
case 3:
green -=2;
if (green ==255) {
green=0;
state = 4;
}
break;
case 4:
red ++;
if (red == 32) {
red = 31;
state = 5;
}
break;
case 5:
blue --;
if (blue == 255) {
blue = 0;
state = 0;
}
break;
}
colour = red<<11 | green<<5 | blue;
}
// The standard ADAFruit font still works as berfore
tft.setTextColor(ILI9341_BLACK, ILI9341_BLACK); // Note these fonts do not plot the background colour
tft.setCursor (68, 5);
tft.print("Original ADAfruit font!");
// The new larger fonts do not use the .setCursor call, coords are embedded
tft.setTextColor(ILI9341_BLACK); // Do not plot the background colour
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
tft.drawCentreString("Font size 2",120,14,2); // Draw text centre at position 120, 14 using font 2
tft.drawCentreString("Font size 4",120,30,4); // Draw text centre at position 120, 30 using font 4
tft.drawCentreString("12.34",120,54,6); // Draw text centre at position 120, 54 using font 6
tft.drawCentreString("12.34 is in font size 6",120,92,2); // Draw text centre at position 120, 92 using font 2
// Note the x position is the top of the font!
// draw a floating point number
float pi = 3.14159; // Value to print
int precision = 3; // Number of digits after decimal point
int xpos = 90; // x position
int ypos = 110; // y position
int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : . a p m
xpos+=tft.drawFloat(pi,precision,xpos,ypos,font); // Draw rounded number and return new xpos delta for next print position
tft.drawString(" is pi",xpos,ypos,font); // Continue printing from new x position
}
}

View File

@ -0,0 +1,225 @@
/*
Sow all the fonts.
Only font sizes 2, 4, 6 and 7 are implemented in the Adafruit_GFX_AS library.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Alan Senior 10/1/2015
Colours:
code color
0x0000 Black
0xFFFF White
0xBDF7 Light Gray
0x7BEF Dark Gray
0xF800 Red
0xFFE0 Yellow
0xFBE0 Orange
0x79E0 Brown
0x7E0 Green
0x7FF Cyan
0x1F Blue
0xF81F Pink
*/
#define sclk 6 // Don't change
#define mosi 4 // Don't change
#define cs 8
#define dc 10
#define rst 9 // you can also connect this to the Arduino reset
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_AS.h> // Hardware-specific library
#include <SPI.h>
Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
tft.init();
tft.setRotation(1);
}
void loop() {
tft.setTextSize(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.drawString(" !\"#$%&'()*+,-./0123456",0,0,2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL",0,16,2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`",0,32,2);
tft.drawString("abcdefghijklmnopqrstuvw",0,48,2);
int xpos=0;
xpos+=tft.drawString("xyz{|}~",0,64,2);
tft.drawChar(127,xpos,64,2);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.drawString(" !\"#$%&'()*+,-.",0,0,4);
tft.drawString("/0123456789:;",0,26,4);
tft.drawString("<=>?@ABCDE",0,52,4);
tft.drawString("FGHIJKLMNO",0,78,4);
tft.drawString("PQRSTUVWX",0,104,4);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.drawString("YZ[\\]^_`abc",0,0,4);
tft.drawString("defghijklmno",0,26,4);
tft.drawString("pqrstuvwxyz",0,52,4);
xpos=0;
xpos+=tft.drawString("{|}~",0,78,4);
tft.drawUnicode(127,xpos,78,4);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_BLUE);
tft.drawString("012345",0,0,6);
tft.drawString("6789",0,40,6);
tft.drawString("apm-:.",0,80,6);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED);
tft.drawString("0123",0,0,7);
tft.drawString("4567",0,60,7);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.drawString("890:.",0,0,7);
tft.drawString("",0,60,7);
delay(4000);
tft.setTextSize(2);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.drawString(" !\"#$%&'()*+,-./0123456",0,0,2);
tft.drawString("789:;<=>?@ABCDEFGHIJKL",0,32,2);
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`",0,64,2);
tft.drawString("abcdefghijklmnopqrstuvw",0,96,2);
xpos=0;
xpos+=tft.drawString("xyz{|}~",0,128,2);
tft.drawChar(127,xpos,128,2);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.drawString(" !\"#$%&'()*+,-.",0,0,4);
tft.drawString("/0123456789:;",0,52,4);
tft.drawString("<=>?@ABCDE",0,104,4);
tft.drawString("FGHIJKLMNO",0,156,4);
tft.drawString("PQRSTUVWX",0,208,4);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.drawString("YZ[\\]^_`abc",0,0,4);
tft.drawString("defghijklmno",0,52,4);
tft.drawString("pqrstuvwxyz",0,104,4);
xpos=0;
xpos+=tft.drawString("{|}~",0,156,4);
tft.drawUnicode(127,xpos,156,4);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_BLUE);
tft.drawString("01234",0,0,6);
tft.drawString("56789",0,80,6);
tft.drawString("apm-:.",0,160,6);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED);
tft.drawString("0123",0,0,7);
tft.drawString("4567",0,120,7);
delay(4000);
tft.fillScreen(ILI9341_BLACK);
tft.drawString("890:.",0,0,7);
tft.drawString("",0,120,7);
delay(4000);
tft.setTextColor(ILI9341_MAGENTA, ILI9341_WHITE);
tft.drawString(">>That's all<< ",0,180,4);
delay(4000);
}
void rainbow(int ystart, int ylen)
{
red = 31;
green = 0;
blue = 0;
state = 0;
colour = red << 11;
for (int i = 0; i<160; i++) {
tft.drawFastVLine(i, ystart, ylen, colour);
switch (state) {
case 0:
green +=2;
if (green == 64) {
green=63;
state = 1;
}
break;
case 1:
red--;
if (red == 255) {
red = 0;
state = 2;
}
break;
case 2:
blue ++;
if (blue == 32) {
blue=31;
state = 3;
}
break;
case 3:
green -=2;
if (green ==255) {
green=0;
state = 4;
}
break;
case 4:
red ++;
if (red == 32) {
red = 31;
state = 5;
}
break;
case 5:
blue --;
if (blue == 255) {
blue = 0;
state = 0;
}
break;
}
colour = red<<11 | green<<5 | blue;
}
}