Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino with TFT (2_8")

By: a guest on Nov 26th, 2012  |  syntax: C++  |  size: 20.14 KB  |  views: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // To whom it may concern,
  2. // the huge matrix called "fontArray" is stored in the PROGMEM
  3. // the functions which call out to it work properly, and
  4. // adding it increased how much we could add to our program before it stopped working.  
  5. // (more about progmem: ) http://www.arduino.cc/playground/Main/PROGMEM
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. #include <Adafruit_GFX.h>    // Core graphics library
  13. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  14. // #include <madData.h>         // Font Driver by Sam and Adrian
  15. #include <avr/io.h>
  16. #include <avr/pgmspace.h>
  17.  
  18. // The control pins for the LCD can be assigned to any digital or
  19. // analog pins...but we'll use the analog pins as this allows us to
  20. // double up the pins with the touch screen (see the TFT paint example).
  21. #define LCD_CS A3 // Chip Select goes to Analog 3
  22. #define LCD_CD A2 // Command/Data goes to Analog 2
  23. #define LCD_WR A1 // LCD Write goes to Analog 1
  24. #define LCD_RD A0 // LCD Read goes to Analog 0
  25.  
  26. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  27.  
  28. // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
  29. // For the Arduino Uno, Duemilanove, Diecimila, etc.:
  30. //   D0 connects to digital pin 8  (Notice these are
  31. //   D1 connects to digital pin 9   NOT in order!)
  32. //   D2 connects to digital pin 2
  33. //   D3 connects to digital pin 3
  34. //   D4 connects to digital pin 4
  35. //   D5 connects to digital pin 5
  36. //   D6 connects to digital pin 6
  37. //   D7 connects to digital pin 7
  38. // For the Arduino Mega, use digital pins 22 through 29
  39. // (on the 2-row header at the end of the board).
  40.  
  41. // Assign human-readable names to some common 16-bit color values:
  42. #define BLACK   0x0000
  43. #define RED     0xF800
  44. #define GREEN   0x07E0
  45.  
  46.  
  47. // #define      BLUE    0x001F
  48. // #define CYAN    0x07FF
  49. // #define MAGENTA 0xF81F
  50. // #define YELLOW  0xFFE0
  51. // #define WHITE   0xFFFF
  52.  
  53. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  54. // If using the shield, all control and data lines are fixed, and
  55. // a simpler declaration can optionally be used:
  56. // Adafruit_TFTLCD tft;
  57.  
  58. #define wrap   TRUE;  // text wrapping ON
  59.  
  60. PROGMEM int fontArray[][84]={
  61.   //0
  62.   {7 , 8 , 9 , 10, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 33, 34, 35, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  63.   {16, 12, 10, 8 , 7 , 6 , 33, 5 , 37, 4 , 39, 4 , 40, 3 , 41, 3 , 42, 3 , 42, 3 , 42, 3 , 42, 3 , 42, 3 , 42, 3 , 42, 3 , 42, 3 , 41, 3 , 40, 4 , 39, 4 , 38, 5 , 35, 5 , 29, 6 , 8 , 10, 12, 18 ,0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  64.   {19, 26, 30, 34, 36, 10, 11, 8 , 8 , 7 , 6 , 5 , 6 , 5 , 5 , 5 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 5 , 5 , 6 , 5 , 6 , 6 , 7 , 6 , 9 , 9 , 16, 14, 36, 32, 28, 24, 12 ,0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  65.  
  66.   //1
  67.   {8 , 9 , 9 , 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  68.   {11, 9 , 41, 9 , 41, 8 , 41, 7 , 41, 7 , 41, 6 , 41, 5 , 41, 5 , 41, 4 , 41, 3 , 41, 3 , 2 , 2 , 2 , 2 , 3 , 41, 41, 41, 41, 41, 41, 41, 41, 41, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  69.   {2 , 5 , 5 , 5 , 5 , 6 , 5 , 6 , 5 , 6 , 5 , 6 , 5 , 6 , 5 , 6 , 5 , 6 , 5 , 7 , 5 , 43, 44, 44, 44, 44, 43, 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  70.  
  71.   //2
  72.   {16, 13, 11, 9 , 8 , 8 , 8 , 22, 8 , 24, 8 , 25, 25, 26, 26, 26, 26, 26, 26, 25, 25, 25, 24, 24, 23, 22, 22, 21, 20, 19, 18, 17, 17, 16, 15, 14, 13, 12, 11, 10, 9 , 8 , 8 , 7 , 7 , 7 , 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },      
  73.   {2 , 3 , 4 , 5 , 6 , 7 , 8 , 8 , 9 , 9 , 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  74.   {9 , 14, 18, 21, 23, 24, 7 , 10, 5 , 8 , 3 , 8 , 8 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 7 , 7 , 8 , 7 , 7 , 8 , 7 , 8 , 8 , 8 , 8 , 8 , 7 , 7 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 27, 28, 28, 28, 27, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  75.  
  76.   //3
  77.   {16, 13, 11, 9 , 9 , 8 , 8 , 23, 8 , 24, 8 , 25, 26, 26, 26, 26, 26, 25, 25, 24, 23, 21, 12, 12, 11, 11, 12, 12, 23, 25, 26, 27, 27, 27, 28, 28, 27, 27, 27, 8 , 26, 7 , 25, 7 , 24, 7 , 20, 7 , 8 , 9 , 11, 14, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  78.   {2 , 3 , 4 , 5 , 6 , 7 , 8 , 8 , 9 , 9 , 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 43, 44, 45, 46, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  79.   {9 , 14, 18, 21, 22, 24, 7 , 9 , 5 , 8 , 3 , 8 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 8 , 9 , 17, 16, 16, 18, 19, 20, 10, 8 , 8 , 7 , 8 , 8 , 7 , 7 , 8 , 7 , 7 , 1 , 8 , 4 , 9 , 6 , 9 , 11, 12, 25, 22, 20, 16, 10, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  80.  
  81.   //4
  82.   {4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  83.   {31, 29, 27, 26, 24, 22, 21, 19, 31, 17, 31, 16, 31, 14, 31, 12, 31, 11, 31, 9 , 31, 7 , 31, 5 , 31, 4 , 31, 3 , 31, 3 , 31, 2 , 2 , 2 , 2 , 3 , 3 , 3 , 31, 31, 31, 31, 31, 32, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  84.   {5 , 7 , 10, 11, 13, 15, 16, 10, 6 , 11, 6 , 10, 6 , 10, 6 , 11, 6 , 10, 6 , 10, 6 , 11, 6 , 11, 6 , 10, 6 , 9 , 6 , 8 , 6 , 43, 44, 45, 45, 44, 43, 43, 6 , 6 , 6 , 6 , 6 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  85.  
  86.   //5
  87.   {10, 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 17, 9 , 9 , 9 , 9 , 10, 23, 25, 26, 27, 28, 28, 28, 28, 28, 28, 28, 27, 27, 26, 7 , 25, 7 , 24, 7 , 19, 7 , 7 , 8 , 10, 13, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  88.   {3 , 4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 39, 40, 40, 41, 41, 42, 43, 44, 45, 46, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  89.   {22, 23, 23, 23, 23, 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 4 , 18, 20, 21, 23, 22, 10, 9 , 8 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 3 , 8 , 5 , 9 , 10, 13, 24, 23, 20, 17, 10, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  90.  
  91.   //6
  92.   {6 , 7 , 8 , 9 , 10, 11, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 34, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },  
  93.   {20, 15, 12, 10, 9 , 7 , 6 , 5 , 21, 35, 5 , 21, 38, 4 , 20, 40, 4 , 20, 40, 3 , 20, 41, 3 , 20, 41, 3 , 19, 42, 2 , 19, 42, 2 , 19, 42, 2 , 19, 41, 2 , 19, 41, 2 , 19, 41, 2 , 19, 40, 2 , 20, 39, 2 , 20, 38, 2 , 20, 34, 3 , 21, 3 , 21, 3 , 22, 4 , 23, 25, 27, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },  
  94.   {13, 23, 28, 32, 34, 37, 39, 11, 6 , 11, 8 , 5 , 8 , 8 , 6 , 6 , 6 , 5 , 7 , 7 , 5 , 6 , 6 , 5 , 6 , 5 , 6 , 5 , 6 , 6 , 5 , 6 , 6 , 5 , 5 , 6 , 6 , 5 , 6 , 6 , 5 , 6 , 6 , 5 , 6 , 6 , 6 , 6 , 7 , 6 , 7 , 7 , 6 , 11, 11, 5 , 23, 6 , 22, 6 , 20, 5 , 18, 15, 10, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  95.  
  96.   //7
  97.   {6 , 6 , 6 , 6 , 6 , 28, 27, 27, 26, 26, 25, 25, 24, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 20, 19, 19, 18, 18, 17, 17, 16, 16, 15, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 13, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  98.   {3 , 4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  99.   {28, 29, 29, 29, 29, 6 , 7 , 6 , 7 , 7 , 7 , 7 , 7 , 7 , 6 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 6 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 7 , 8 , 7 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  100.  
  101.   //8
  102.   {16, 13, 11, 10, 9 , 8 , 23, 8 , 25, 7 , 26, 7 , 27, 7 , 27, 7 , 27, 7 , 27, 7 , 27, 7 , 27, 7 , 26, 8 , 25, 8 , 24, 9 , 23, 10, 21, 11, 12, 14, 14, 12, 11, 9 , 21, 8 , 23, 8 , 25, 7 , 26, 6 , 27, 6 , 28, 6 , 28, 5 , 28, 5 , 29, 5 , 28, 5 , 28, 6 , 28, 6 , 27, 6 , 26, 7 , 23, 8 , 8 , 10, 11, 15},
  103.   {2 , 3 , 4 , 5 , 6 , 7 , 7 , 8 , 8 , 9 , 9 , 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 43, 44, 45, 46},
  104.   {9 , 15, 19, 21, 23, 10, 9 , 7 , 8 , 7 , 7 , 7 , 6 , 6 , 7 , 6 , 7 , 6 , 6 , 6 , 6 , 7 , 6 , 7 , 7 , 7 , 7 , 9 , 8 , 9 , 8 , 10, 9 , 18, 15, 12, 14, 17, 20, 9 , 11, 9 , 10, 7 , 8 , 7 , 8 , 7 , 7 , 7 , 7 , 6 , 7 , 7 , 7 , 7 , 6 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 8 , 10, 10, 24, 24, 20, 17, 10},
  105.  
  106.   //9
  107.   {6 , 7 , 8 , 8 , 9 , 9 , 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 30, 31, 32, 33, 34, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  108.   {14, 10, 8 , 40, 7 , 40, 6 , 40, 5 , 41, 4 , 41, 4 , 20, 41, 3 , 22, 41, 3 , 23, 42, 3 , 24, 42, 2 , 24, 42, 2 , 24, 42, 2 , 25, 41, 2 , 25, 41, 2 , 24, 41, 2 , 24, 40, 2 , 24, 40, 2 , 24, 39, 3 , 24, 38, 3 , 23, 36, 3 , 23, 34, 4 , 22, 31, 5 , 5 , 7 , 8 , 10, 13, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  109.   {5 , 13, 17, 5 , 19, 6 , 21, 6 , 23, 5 , 24, 6 , 8 , 9 , 6 , 7 , 7 , 6 , 6 , 6 , 5 , 5 , 6 , 5 , 6 , 6 , 5 , 6 , 6 , 5 , 5 , 5 , 6 , 5 , 5 , 6 , 5 , 6 , 6 , 6 , 6 , 6 , 6 , 5 , 6 , 6 , 5 , 7 , 6 , 5 , 7 , 7 , 6 , 9 , 9 , 5 , 10, 13, 6 , 12, 37, 36, 33, 30, 25, 19, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  110.  
  111.   //dp
  112.   {8 , 6 , 6 , 5 , 5 , 5 , 5 , 6 , 6 , 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  113.   {37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  114.   {4 , 8 , 8 , 10, 10, 10, 10, 8 , 8 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  115.  
  116.   //W
  117.   {4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  118.   {7 , 7 , 7 , 7 , 7 , 7 , 8 , 12, 17, 21, 25, 30, 34, 35, 32, 28, 23, 19, 15, 11, 8 , 7 , 7 , 7 , 7 , 7 , 7 , 8 , 11, 15, 19, 23, 27, 31, 35, 35, 31, 26, 22, 18, 13, 9 , 7 , 7 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
  119.   {5 , 9 , 13, 17, 21, 25, 28, 27, 25, 22, 18, 13, 9 , 8 , 11, 15, 20, 23, 23, 23, 22, 19, 15, 12, 14, 18, 22, 25, 25, 25, 23, 20, 16, 12, 8 , 8 , 12, 17, 21, 23, 25, 25, 23, 19, 15, 12, 8 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
  120. };
  121.  
  122. void setup(void) {
  123.   Serial.begin(9600);
  124.   Serial.println("TFT LCD test");
  125.  
  126. #ifdef USE_ADAFRUIT_SHIELD_PINOUT
  127.   Serial.println("Using Adafruit 2.8\" TFT Arduino Shield Pinout");
  128. #else
  129.   Serial.println("Using Adafruit 2.8\" TFT Breakout Board Pinout");
  130. #endif
  131.  
  132.   tft.reset();
  133.  
  134.   uint16_t identifier = tft.readID();
  135.  
  136.  
  137.   if(identifier == 0x9325) {
  138.     Serial.println(PSTR("Found ILI9325 LCD driver"));
  139.   } else if(identifier == 0x9328) {
  140.     Serial.println(PSTR("Found ILI9328 LCD driver"));
  141.   } else if(identifier == 0x7575) {
  142.     Serial.println(PSTR("Found HX8347G LCD driver"));
  143.   } else {
  144.     Serial.print(PSTR("Unknown LCD driver chip: "));
  145.     Serial.println(identifier, HEX);
  146.     Serial.println(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
  147.     Serial.println(PSTR("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
  148.     Serial.println(PSTR("should appear in the library header (Adafruit_TFT.h)."));
  149.     Serial.println(PSTR("If using the breakout board, it should NOT be #defined!"));
  150.     Serial.println(PSTR("Also if using the breakout, double-check that all wiring"));
  151.     Serial.println(PSTR("matches the tutorial."));
  152.     return;
  153.   }
  154.  
  155.  
  156.   tft.begin(identifier);
  157.   tft.setRotation(3);
  158.   tft.fillScreen(BLACK);               // screen background is black  
  159.   Serial.begin(9600);
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. void loop(void){
  167.   boolean a=true;
  168.   for (int k=0; k<50; k++){
  169.     a=(k%2==1);
  170.     float aMillion = 1000000;
  171.     drawArrow(GREEN, a);
  172.     printWatts(aMillion * senseWattage());
  173.     delay(300);
  174.     tft.fillScreen(BLACK);               // screen background is black  
  175.   }
  176. } /// end of main loop
  177.  
  178.  
  179.  
  180. float senseWattage(){
  181.  
  182.   int voltageBits = analogRead(A0);              // read the input on analog pin 0:
  183.   float voltageVolts = voltageBits*0.00488759;   // converts bits to volts
  184.   float sensedVoltage = voltageVolts*8.5965;     // Scalar determined by the voltage divider to pin A0
  185.  
  186.   int currentValue = analogRead(A1);
  187.   float sensedCurrent = currentValue * 0.00488759;  // convert current sensor voltage output from bits to volts
  188.   sensedCurrent = (sensedCurrent-2.5) * 10 + 0.3;   // for -30 use 15.15+0.3 for -20 use 10.0+0.3
  189.  
  190.   return sensedCurrent * sensedVoltage;
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197. void drawArrow(int color, boolean left)
  198. {  /// initialize all points as if it's drawing a right arrow, then :::
  199.   int rectX= -38;
  200.   int triTopBot= 30;
  201.   int triPoint= 120;
  202.  
  203.    if (left) //          ::: switch them if it's facing left.  
  204.    {
  205.      rectX*= -1;         //rectX= 38;  
  206.      triTopBot*= -1;     //triTopBot= -30;
  207.      triPoint*= -1;      //triPoint= -120;
  208.    }
  209.  
  210.       tft.fillRect(93+rectX, 41, 135, 110, color); //x, y, w, h, color **Origin is bottom left
  211.       tft.fillTriangle(161+triTopBot, 186, 160+triTopBot, 6, 160+triPoint, 96, color); //3 pairs of vertices, color
  212. }  
  213.    
  214.    
  215.    
  216.    
  217. // print char input: signed char number, int x_coord, int y_coord, int color) ;
  218.    //  XY are top left of char print spot
  219. // print char output: unsigned int - increment the cursor by this many pixels
  220. unsigned int printChar(signed char input, unsigned int x, unsigned int y, unsigned int color ){
  221.  
  222. // 0   1   2   3   4   5   6   7   8   9   .   W
  223. // 0   3   6   9   12  15  18  21  24  27  30  33
  224. // V   V   H   H   V   H   V   H   H   V   H   V
  225.  
  226.   unsigned int charWidth=42;  
  227.   if (input==-16){ // input is a space.  
  228.     return 20;}   // draw nothing, return 20 so the calling function knows to increment its cursor
  229.   else if(input<0){   //decimal point. starts at 30, is H
  230.     input=10;    // make the next bit of lookup table work in my favor.
  231.     charWidth=20;}
  232.   else if(input>9){// W.  starts at 33, is drawn with H
  233.    input=11;     // make the next bit of lookup table work in my favor.  
  234.    charWidth=56; }
  235.  
  236.   byte row_start=input*3;          // holds the offset for the font vector in pgmem
  237.   byte dir_lookup[] = {1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1}; // a lookup table for the draw-directions
  238.   byte draw_dir=dir_lookup[input]; // indicates the draw function to draw horizontal (0) or vertical (1) for each character
  239.  
  240.   // now draw_dir is either 0 (indicating horizontal) or 1 (indicating vertical)
  241.   // and row_start is the row in the pgmem table at which the current piece of the font vector is stored.
  242.  
  243.   int i=0;  // conumn pointer for fetching vector information from pgmem.  
  244.   while (pgm_read_byte(&fontArray[row_start][i])>0){ // loop until the zero point is found.  
  245.     if (draw_dir==1){
  246.       tft.drawFastVLine(
  247.         x+pgm_read_byte(&fontArray[row_start  ][i]),
  248.         y+pgm_read_byte(&fontArray[row_start+1][i]),
  249.         0+pgm_read_byte(&fontArray[row_start+2][i]),
  250.         color);}
  251.     else {
  252.       tft.drawFastHLine(
  253.         x+pgm_read_byte(&fontArray[row_start  ][i]),
  254.         y+pgm_read_byte(&fontArray[row_start+1][i]),
  255.         0+pgm_read_byte(&fontArray[row_start+2][i]),
  256.         color);}  
  257.     i++;  // increment the column pointer i
  258.   }
  259.  
  260.   return charWidth;
  261. }
  262.  
  263.  
  264.  
  265.  
  266. // Function to print a calculated wattage value on the screen
  267. // Pass the value in in microwatts.  MICROWATTS
  268. // the integer 'digits' is how many digits to print.  Decimal point is not included.  
  269. void printWatts(signed long wattage){  // that long has the unit of MICROWATTS.  Don't you forget it.
  270.  
  271.   // now the input wattage (unit: uW) is to be converted into a string
  272.   // the conversion from long-int to string is implicit
  273.  
  274.     String wattage_left   = String(wattage/1000000);                  // get numbers from the left of the dp
  275.     String wattage_right  = String(wattage%1000000);                  // get the stuff after the decimal point, seperately  
  276.     while (wattage_right.length()<6){
  277.       wattage_right = "0"+wattage_right;                              // fix the problem of the dropped zero after the dp
  278.     }      
  279.  
  280.     String dp = String(".");                                          // Decimal point string to be used in concatenation
  281.     String wattage_string = wattage_left + dp + wattage_right;        // concatentate strings, add the decimal point
  282.    
  283.     String units = String(" W");
  284.     wattage_string = wattage_string.substring(0,5) + units;
  285.  
  286.     if (wattage==0){wattage_string=String("0.000 W");}
  287.    
  288.     unsigned int myCursor[]={10, 187};                                // holds the location to print to
  289.     for (int i=0; i<7; i++){
  290.       myCursor[0] = myCursor[0] + printChar((signed char)byte(wattage_string.charAt(i))-48, myCursor[0], myCursor[1], GREEN);
  291.     }
  292. }
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300. /*
  301. unsigned long testText() {
  302.   tft.fillScreen(BLACK);
  303.   unsigned long start = micros();
  304.   tft.setCursor(0, 0);
  305.   tft.setTextColor(WHITE);  tft.setTextSize(1);
  306.   tft.println("Hello World!");
  307.   tft.setTextColor(YELLOW); tft.setTextSize(2);
  308.   tft.println(1234.56);
  309.   tft.setTextColor(RED);    tft.setTextSize(3);
  310.   tft.println(0xDEADBEEF, HEX);
  311.   tft.println();
  312.   tft.setTextColor(GREEN);
  313.   tft.setTextSize(5);
  314.   tft.println("Groop");
  315.   tft.setTextSize(2);
  316.   tft.println("I implore thee,");
  317.   tft.setTextSize(1);
  318.   tft.println("my foonting turlingdromes.");
  319.   tft.println("And hooptiously drangle me");
  320.   tft.println("with crinkly bindlewurdles,");
  321.   tft.println("Or I will rend thee");
  322.   tft.println("in the gobberwarts");
  323.   tft.println("with my blurglecruncheon,");
  324.   tft.println("see if I don't!");
  325.   return micros() - start;
  326. }
  327. */
clone this paste RAW Paste Data