Advertisement
Hirsw0w

CodeCArduino

Oct 16th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_FT6206.h>
  3. #include <Adafruit_ILI9341.h>
  4. #include <Adafruit_GFX.h>
  5.  
  6. /* Defines */
  7. #define TFT_CS 10
  8. #define TFT_DC 9
  9.  
  10. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
  11.  
  12. extern uint8_t SmallFont[];
  13. extern uint8_t BigFont[];
  14. /*
  15.  
  16. short pageId = 0;
  17.  
  18. int buttons[MAX_BUTTONS][5];
  19. short bCount = 0;
  20. short startGameButton = -1;
  21. */
  22.  
  23. int x = 50;
  24. int y = 0;
  25. int mode = 0;
  26. int angle = 0;
  27. void setup() {
  28. Serial.begin(9600);
  29. tft.begin();
  30. tft.fillScreen(ILI9341_BLACK);
  31. }
  32.  
  33. void loop() {
  34. tft.fillRect(x,y,2,2,0xffff);
  35. if(mode == 1) tft.fillRect(x,y++,2,2,0xffff);
  36. else if(mode == 3) tft.fillRect(x,y--,2,2,0xffff);
  37. else if(mode == 2) tft.fillRect(x--,y,2,2,0xffff);
  38. else if(mode == 4) tft.fillRect(x++,y,2,2,0xffff);
  39.  
  40. if (Serial.available() > 0) {
  41. // read the incoming byte:
  42. byte incomingByte = Serial.read();
  43. int tempmode = 0;
  44. if(incomingByte == 'a')Serial.println("hey1"), tempmode = 1;
  45. else if(incomingByte == 'd')Serial.println("hey2"), tempmode = 3;
  46. else if(incomingByte == 'w') Serial.println("hey3"),tempmode = 2;
  47. else if(incomingByte == 's') Serial.println("hey4"),tempmode = 4;
  48. }
  49. delay(200);
  50. /*tft.fillScreen(ILI9341_BLACK);
  51. PrintText(50,y++);
  52. delay(10);*/
  53. }
  54.  
  55. void PrintText(int x,int y) {
  56. tft.setCursor(x,y);
  57. tft.setTextColor(ILI9341_WHITE);
  58. tft.setTextSize(3);
  59. tft.println("Blue Wins");
  60. }
  61.  
  62. /*
  63.  
  64. void drawHomeScreen() {
  65. pageId = 1;
  66. myGLCD.setBackColor(0,0,0);
  67. PrintText("CatchMe",CENTER, 10,255,255,255,BigFont);
  68. startGameButton = CreateButton("Start Game",25,25,100,50, 255,255,255 , 0,0,0);
  69. }
  70.  
  71. void PrintText(text[], x,y,r = 255,g = 255,b = 255, font[] = SmallFont) {
  72. myGLCD.setColor(r,g,b);
  73. myGLCD.setFont(font);
  74. myGLCD.print(text,x,y);
  75. }
  76.  
  77. short CreateButton(text[], x,y, width,height, boxr = 255, boxg = 255,boxb = 255, r = 255, g = 255, b = 255) {
  78. myGLCD.setColor(boxr, boxg, boxb);
  79. myGLCD.fillRoundRect (x, y, width, height);
  80. myGLCD.setFont(BigFont);
  81. myGLCD.setBackColor(r, g, b);
  82. myGLCD.print(text, x, y);
  83. buttons[bCount][0] = x;
  84. buttons[bCount][1] = y;
  85. buttons[bCount][2] = width;
  86. buttons[bCount][3] = height;
  87. buttons[bCount][4] = pageId;
  88. return bCount++;
  89. }
  90.  
  91. void loop() {
  92. if (myTouch.dataAvailable()) {
  93. myTouch.read();
  94. x=myTouch.getX(); // X coordinate where the screen has been pressed
  95. y=myTouch.getY(); // Y coordinates where the screen has been pressed
  96.  
  97. short pressedButton = -1;
  98. for(short i = 0;i < MAX_BUTTONS;i++) {
  99. if(buttons[i][4] != pageId)
  100. continue;
  101.  
  102. if(x >= buttons[i][0] && x <= (buttons[i][0] + buttons[i][2]) && y >= buttons[i][1] && y <= (buttons[i][1] + buttons[i][3])) {
  103. pressedButton = i;
  104. break;
  105. }
  106. }
  107.  
  108. switch(pressedButton) {
  109. case startGameButton: {
  110. // Start Game
  111. }
  112. }
  113. }
  114. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement