Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_TFTLCD.h> // Hardware-specific library
- // The control pins for the LCD can be assigned to any digital or
- // analog pins...but we'll use the analog pins as this allows us to
- // double up the pins with the touch screen (see the TFT paint example).
- #define LCD_CS A3 // Chip Select goes to Analog 3
- #define LCD_CD A2 // Command/Data goes to Analog 2
- #define LCD_WR A1 // LCD Write goes to Analog 1
- #define LCD_RD A0 // LCD Read goes to Analog 0
- #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
- // Assign human-readable names to some common 16-bit color values:
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- // If using the shield, all control and data lines are fixed, and
- // a simpler declaration can optionally be used:
- // Adafruit_TFTLCD tft;
- int teamColor;
- void drawTeam(char team) {
- if (team == 'T') {
- tft.fillRect(0, 0, 320, 240, RED);
- teamColor = RED;
- }
- else {
- teamColor = BLUE;
- tft.fillRect(0, 0, 320, 240, BLUE);
- }
- }
- void drawHealthArmor(int health, int armor) {
- tft.setCursor(150, 210);
- tft.setTextColor(BLACK);
- tft.setTextSize(3);
- tft.print(health);
- tft.fillRect(213, 210, 4, 20, BLACK);
- tft.fillRect(205, 218, 20, 4, BLACK);
- tft.setCursor(235, 210);
- tft.print(armor);
- tft.setCursor(290, 210);
- tft.print('A');
- }
- void drawName(char * name) {
- tft.setCursor(10, 210);
- tft.setTextColor(BLACK);
- tft.setTextSize(3);
- tft.print(name);
- }
- void drawBombTime(int time) {
- tft.setCursor(115, 90);
- tft.setTextColor(BLACK);
- tft.setTextSize(8);
- tft.print(time);
- }
- void drawExplode() {
- tft.setCursor(60, 90);
- tft.setTextColor(BLACK);
- tft.setTextSize(8);
- tft.fillRect(60, 90, 150, 50, teamColor);
- tft.print("BOOM!");
- }
- void setup()
- {
- tft.reset();
- uint16_t identifier = tft.readID();
- tft.begin(identifier);
- tft.setRotation(1);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- drawTeam('T');
- drawHealthArmor(120, 100);
- drawName("dada");
- drawBombTime(30);
- drawExplode();
- delay(2000);
- // delay(200);
- // drawTeam('C');
- // delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement