It works...
/*
QBF - The Quick Brown Fox
by M. Ray Burnette ==> Public Domain
05/06/2014
Arduino 1.0.5r2 Board=Arduino Pro Mini (328) Profile= Arduino Pro or Pro Mini (5V, 16MHz)
Program: 11990 bytes (.text + .data + .bootloader)
Data: 566 bytes (.data + .bss + .noinit)
Primary Color definitions for TFT display: int_16
ILI9340_BLACK 0x0000, ILI9340_BLUE 0x001F, ILI9340_RED 0xF800, ILI9340_GREEN 0x07E0
ILI9340_CYAN 0x07FF, ILI9340_MAGENTA 0xF81F, ILI9340_YELLOW 0xFFE0, ILI9340_WHITE 0xFFFF
*/
// See tab/file License.h for use/rights information regarding Adafruit library
#include <SPI.h>
#include <Serial.h> // hardware serial Rx, Tx on 328
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9340.h>
#include <Streaming.h>
// Pinouts for ILI9340 2.2" 240x320 TFT LCD SPI interface (SD card not attached)
// Pro Mini LCD Display UNO pins
#define _sclk 13 // J2 pin 7 13
#define _miso 12 // pin 9 12
#define _mosi 11 // pin 6 11
#define _cs 10 // pin 3 10
#define _dc 9 // pin 5 9
#define _rst 8 // pin 4 8
// Do Note use PROGMEM with Pro Micro ... Bootloader lockup Reason unknown... need confirmation
String sBlank = " " ; // 26 characters == 1 line
boolean lFlag = true ;
boolean lFoxActive = false ;
const int yCord[] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224} ;
byte index ;
int nRow = 0 ; // 0 - 14, line 1 - 15
int nCol = 0 ; // 0 - 16
int nLCD = 0 ; // 1 - 390 arranged as 15 lines x 26 characters
int nLn = 1 ; // current line, 1-based
int cPostn = 0 ;
char cWatchChar = '.' ; // ... OR can be any printable character!
String cFoxString = "The quick brown fox jumped over the lazy dog's back.\0" ;
// Using software SPI is really not suggested, its incredibly slow... Use hardware SPI
// Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
Adafruit_ILI9340 lcd = Adafruit_ILI9340(_cs, _dc, _rst);
void setup()
{
lcd.begin() ; // 2.2" GLCD SPI 240x320 used in LANDSCAPE
lcd.setRotation(3); // landscape with SPI conn J2 to LEFT side.
lcd.fillScreen(ILI9340_BLACK);
lcd.setCursor(0, 0);
lcd.setTextColor(ILI9340_CYAN) ;
lcd.setTextSize(3); // Medium 17 char / line 10Pixels Wide x 25 Pixels / line
pinMode( 4, INPUT) ; // lFoxActive Low = True
digitalWrite( 4, HIGH); // turn on pullup resistor
pinMode( 6, INPUT) ; // BAUD hi = 9600 lo = 4800 for setting common GPS rates
digitalWrite( 6, HIGH); // turn on pullup resistor
delay (100) ;
lcd.setCursor(0, 131);
if (! digitalRead(4) )
{
lFoxActive = true ;
lcd << "Send == ON" ;
} else {
// lFoxActive = false ;
lcd << "Send == OFF" ;
}
lcd.setCursor(0, 157);
if( digitalRead(6) ) {
Serial.begin(9600) ; // 1st serial port because 'Serial' translates to USB comm:
lcd << "BAUD == 9600" ;
} else {
Serial.begin(4800) ; // 1st serial port because 'Serial' translates to USB comm:
lcd << "BAUD == 4800" ;
}
lcd.setCursor(0, 183);
lcd << "Seek == " ;
lcd.setTextColor(ILI9340_RED) ;
lcd << cWatchChar ;
// Display 'credits' in color on GLCD
lcd.setCursor(0, 0) ;
lcd.setTextColor(ILI9340_BLUE); lcd << "G" ;
lcd.setTextColor(ILI9340_RED); lcd << "L" ;
lcd.setTextColor(ILI9340_GREEN); lcd << "C" ;
lcd.setTextColor(ILI9340_YELLOW); lcd << "D " ;
lcd.setTextColor(ILI9340_MAGENTA); lcd << "T" ;
lcd.setTextColor(ILI9340_BLUE); lcd << "e" ;
lcd.setTextColor(ILI9340_CYAN); lcd << "r" ;
lcd.setTextColor(ILI9340_RED); lcd << "m" ;
lcd.setTextColor(ILI9340_GREEN); lcd << "i" ;
lcd.setTextColor(ILI9340_YELLOW); lcd << "n" ;
lcd.setTextColor(ILI9340_WHITE); lcd << "a" ;
lcd.setTextColor(ILI9340_BLUE); lcd << "l " ;
lcd.setTextColor(ILI9340_CYAN); lcd << "b" ;
lcd.setTextColor(ILI9340_MAGENTA); lcd << "y \r \n" ;
lcd.setTextColor(ILI9340_BLUE); lcd << "R" ;
lcd.setTextColor(ILI9340_CYAN); lcd << "a" ;
lcd.setTextColor(ILI9340_MAGENTA); lcd << "y " ;
lcd.setTextColor(ILI9340_BLUE); lcd << "B" ;
lcd.setTextColor(ILI9340_RED); lcd << "u" ;
lcd.setTextColor(ILI9340_GREEN); lcd << "r" ;
lcd.setTextColor(ILI9340_YELLOW); lcd << "n" ;
lcd.setTextColor(ILI9340_WHITE); lcd << "e" ;
lcd.setTextColor(ILI9340_CYAN); lcd << "t" ;
lcd.setTextColor(ILI9340_MAGENTA); lcd << "t" ;
lcd.setTextColor(ILI9340_BLUE); lcd << "e" ;
lcd.setCursor(0, 224);
lcd.setTextSize(2);
lcd.print("May 2014 Version 1.03") ;
delay(2000) ; // credits
lcd.fillScreen(ILI9340_BLACK) ;
lcd.setTextColor(ILI9340_GREEN, ILI9340_BLACK) ;
// Put something on the blank display tft.drawLine( x1, y1, x2, y2, color);
lcd.drawLine( 0, 7, 310, 7, ILI9340_MAGENTA);
lcd.setTextSize(2) ;
lcd.setCursor(0, 0) ;
}
void loop()
{
if ( ! lFlag ) // Clean-up after moving to a new line
{
nCol = 0 ; // align character pointer to "x" home
index = int(nLCD / 26) ; // character pointer to current-line to graphic "y" lookup of home character
nRow = yCord[ index ] ; // [0 - 14] ==> lines 1 - 15
lcd.setCursor (nCol, nRow) ; // restore cursor to home character of current line
lcd.drawLine( 0, (nRow + 7), 310, (nRow + 7), ILI9340_YELLOW);
lcd.setTextColor(ILI9340_GREEN, ILI9340_BLACK) ;
lFlag = true ; // toggle off until needed again
}
if (Serial.available())
{
char c = Serial.read() ;
if (c) // non-Null character
{
// if ( c == 10 ) c = 13 ; // translate LF to CR and implement as CR+LF
if( c > 31 && c < 127) // keep non-printables off LCD
{
if ( c == cWatchChar )
{
lcd.setTextColor(ILI9340_RED, ILI9340_BLACK) ;
lcd.print(c) ;
lcd.setTextColor(ILI9340_GREEN, ILI9340_BLACK) ;
} else {
lcd.print(c) ;
}
++nLCD ; // increment character count
}
switch (c) { // Operate upon a few control characters
case 6: // Acknowledge ACK
Serial << 21 ; // NAK
break;
case 7: // bell tone
Serial << (c) ;
break;
case 8: // backspace
break; // not implemented
case 9: // Horizontal tab
break; // not implemented
case 10: // new line
break; // implemented with CR == CR+LF
case 12: // new page, implemented as clear screen == CTRL L
lcd.fillScreen(ILI9340_BLACK) ;
lFlag = false ; nRow = 0 ; nCol = 0 ; nLCD = 0 ; nLn = 1 ;
break;
case 13: // carriage return? Inplement as CR+LF
c = 32 ; // SPACE character
lcd.print(c) ; // Print the CR/LF as a space
for( int X = nLCD; X % 26 !=0; X++) lcd.print(c) ; // clear to end of line with spaces
nRow = (nLCD / 26) + 1 ; // (row == 0, 1, ... 14)
if( nRow > 15 ) nRow = 0 ; // overflow: maintain boundary
index = nRow ; // array index for graphic "Y" position of first character
nCol = 0 ; // "X" Graphic coordinate
nRow = yCord[ index ] ; // Graphic "Y" coordinate via lookup
nLCD = index * 26 ; // 26 characters per line (line = nRow +1)
lcd.setCursor (nCol, nRow) ; // restore cursor to home character of current line
// lFlag = false ; // unneeded because nLCD %26 will == 0
break ;
case 21: // NAK?
Serial << 6 ; // ACK
break;
case 27: // ESC?
lFlag = false ; nRow = 0 ; nCol = 0 ; nLCD = 0 ; nLn = 1 ;
break;
default:
break;
}
if( nLCD % 26 == 0 ) // just printed last character on line?
{
lFlag = false ; // activate clean-up at top of loop before next character
if( nLCD == 390) // last character of last line?
{
nLCD = 0 ;
c = 0 ;
}
}
}
} else {
if( lFoxActive )
{
Serial << cFoxString.charAt( cPostn ) ;
//if( lFoxActive ) Serial1 << "The Quick Brown Fox Jumps Over The Lazy Dog's Back 1234567890!@#$%^&*()-+ \r \n" ;
++ cPostn ;
if( cPostn > cFoxString.length() )
{
cPostn = 0 ;
Serial << "\r" ;
}
}
}
}
The QBF - "The Quick Brown Fox..." For Serial Diags - Community / Exhibition / Gallery - Arduino Forum
/*
// These are the pins used for the UNO
UNO LEO // J2 header pin # on GLCD
#define _sclk 13 15 // 7
#define _miso 12 14 // 9
#define _mosi 11 16 // 6
#define _cs 10 10 // 3
#define _dc 9 9 // 5
#define _rst 8 8 // 4