Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPFD5408_Adafruit_GFX.h>  
  2. #include <SPFD5408_Adafruit_TFTLCD.h>
  3. #include <SPFD5408_TouchScreen.h>
  4.  
  5. #define SENSIBILITY 300
  6. #define MINPRESSURE 10
  7. #define MAXPRESSURE 1000
  8.  
  9. #define YP A2
  10. #define XM A3
  11. #define YM 8  
  12. #define XP 9
  13.  
  14. TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY);
  15. TSPoint p;
  16.  
  17. #define LCD_CS A3
  18. #define LCD_CD A2
  19. #define LCD_WR A1
  20. #define LCD_RD A0
  21. #define LCD_RESET A4
  22.  
  23. #define BLACK   0x0000
  24. #define BLUE    0x001F
  25. #define RED     0xF800
  26. #define GREEN   0x07E0
  27. #define CYAN    0x07FF
  28. #define MAGENTA 0xF81F
  29. #define YELLOW  0xFFE0
  30. #define WHITE   0xFFFF
  31.  
  32. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  33.  
  34. void setup() {
  35.   tft.reset();
  36.   tft.begin(0x9341);
  37.   tft.setRotation(1);
  38.   tft.setTextSize (2);
  39.   tft.setTextColor(WHITE);
  40.   tft.fillScreen(BLACK);
  41.   Serial.begin(9600);
  42. }
  43.  
  44. void loop() {
  45.   drawMainMenu(14,56,1); // temperatura, umidità, menu
  46.   p = waitOneTouch();
  47.   if(p.x < 600){
  48.     Serial.print("prog1");
  49.   } else Serial.print("prog2");
  50.  
  51. }
  52.  
  53. void drawMainMenu(float temp,int hum, int menu) {
  54.   tft.setCursor (10, 15);
  55.   tft.print("Temperatura: ");tft.print(temp);tft.print(" C");
  56.   tft.setCursor (10, 40);
  57.   tft.print("Umidita: ");tft.print(hum);tft.print(" %");
  58.   if(menu==0) {
  59.     tft.drawRect(5, 130, 150, 100, BLUE);
  60.     tft.drawRect(160, 130, 150, 100, GREEN);
  61.     tft.setCursor (40, 170);
  62.     tft.print("Prog. 1");
  63.     tft.setCursor (190, 170);
  64.     tft.print("Prog. 2");
  65.   }
  66.   if(menu==1) {
  67.     tft.drawRect(5, 130, 150, 100, BLUE);
  68.     tft.drawRect(160, 130, 150, 100, GREEN);
  69.     tft.setCursor (50, 170);
  70.     tft.print("STOP");
  71.     tft.setCursor (200, 170);
  72.     tft.print("RESET");
  73.   }
  74.   if(menu==2) {
  75.     tft.drawRect(5, 130, 150, 100, BLUE);
  76.     tft.drawRect(160, 130, 150, 100, GREEN);
  77.     tft.setCursor (50, 170);
  78.     tft.print("START");
  79.     tft.setCursor (200, 170);
  80.     tft.print("RESET");
  81.   }
  82. }
  83.  
  84. TSPoint waitOneTouch() {
  85.   TSPoint p;
  86.   do {
  87.     p= ts.getPoint();
  88.     pinMode(XM, OUTPUT); //Pins configures again for TFT control
  89.     pinMode(YP, OUTPUT);
  90.  
  91.   } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE));
  92.   return p;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement