Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1.  
  2.  
  3. #include <Adafruit_GFX.h> // Core graphics library
  4. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  5.  
  6. // The control pins for the LCD can be assigned to any digital or
  7. // analog pins...but we'll use the analog pins as this allows us to
  8. // double up the pins with the touch screen (see the TFT paint example).
  9. #define LCD_CS A3 // Chip Select goes to Analog 3
  10. #define LCD_CD A2 // Command/Data goes to Analog 2
  11. #define LCD_WR A1 // LCD Write goes to Analog 1
  12. #define LCD_RD A0 // LCD Read goes to Analog 0
  13.  
  14. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  15.  
  16. // Assign human-readable names to some common 16-bit color values:
  17. #define BLACK 0x0000
  18. #define BLUE 0x001F
  19. #define RED 0xF800
  20. #define GREEN 0x07E0
  21. #define CYAN 0x07FF
  22. #define MAGENTA 0xF81F
  23. #define YELLOW 0xFFE0
  24. #define WHITE 0xFFFF
  25.  
  26. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  27. // If using the shield, all control and data lines are fixed, and
  28. // a simpler declaration can optionally be used:
  29. // Adafruit_TFTLCD tft;
  30.  
  31. int teamColor;
  32.  
  33. void drawTeam(char team) {
  34. if (team == 'T') {
  35. tft.fillRect(0, 0, 320, 240, RED);
  36. teamColor = RED;
  37. }
  38. else {
  39. teamColor = BLUE;
  40. tft.fillRect(0, 0, 320, 240, BLUE);
  41. }
  42. }
  43.  
  44. void drawHealthArmor(int health, int armor) {
  45. tft.setCursor(150, 210);
  46. tft.setTextColor(BLACK);
  47. tft.setTextSize(3);
  48. tft.print(health);
  49.  
  50. tft.fillRect(213, 210, 4, 20, BLACK);
  51. tft.fillRect(205, 218, 20, 4, BLACK);
  52.  
  53. tft.setCursor(235, 210);
  54. tft.print(armor);
  55. tft.setCursor(290, 210);
  56. tft.print('A');
  57. }
  58.  
  59. void drawName(char * name) {
  60. tft.setCursor(10, 210);
  61. tft.setTextColor(BLACK);
  62. tft.setTextSize(3);
  63. tft.print(name);
  64. }
  65.  
  66. void drawBombTime(int time) {
  67. tft.setCursor(115, 90);
  68. tft.setTextColor(BLACK);
  69. tft.setTextSize(8);
  70. tft.print(time);
  71. }
  72.  
  73. void drawExplode() {
  74. tft.setCursor(60, 90);
  75. tft.setTextColor(BLACK);
  76. tft.setTextSize(8);
  77. tft.fillRect(60, 90, 150, 50, teamColor);
  78. tft.print("BOOM!");
  79. }
  80.  
  81.  
  82. void setup()
  83. {
  84. tft.reset();
  85.  
  86. uint16_t identifier = tft.readID();
  87. tft.begin(identifier);
  88. tft.setRotation(1);
  89. }
  90.  
  91. void loop() {
  92. // put your main code here, to run repeatedly:
  93. drawTeam('T');
  94. drawHealthArmor(120, 100);
  95. drawName("dada");
  96. drawBombTime(30);
  97. drawExplode();
  98. delay(2000);
  99. // delay(200);
  100. // drawTeam('C');
  101. // delay(2000);
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement