Advertisement
wluijkx

UselessMachine.h

Dec 17th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. #include <SPI.h>
  2.  
  3. #include <Adafruit_GFX.h>
  4.  
  5. #include <Adafruit_ILI9341.h>
  6.  
  7. #include <XPT2046_Touchscreen.h>
  8.  
  9. #include "finger.h"
  10. #include "icons30pt7b.h"
  11.  
  12. #define TFT_CS D0
  13. #define TFT_DC D8
  14. #define TFT_RST -1
  15. #define TS_CS D3
  16.  
  17.  
  18. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
  19. XPT2046_Touchscreen ts(TS_CS);
  20.  
  21. #define BUTTONBG 0x0000
  22. #define BUTTONBGACT 0x7BEF
  23. #define BUTTONEDGE 0x9492
  24. #define TEXTCOLOR 0xFFFF
  25. #define SCREENCOLOR 0x0000
  26. #define TOGGLEON 0x660A
  27. #define TOGGLEOFF 0x8430
  28.  
  29. //Translation of touchscreen coordinates to pixels
  30. #define TS_MINX 230
  31. #define TS_MAXX 3600
  32.  
  33. #define TS_MINY 330
  34. #define TS_MAXY 3700
  35.  
  36. //Drukbereik touchscreen
  37. #define MINPRESSURE 400
  38. #define MAXPRESSURE 3000
  39.  
  40. #define BLACK 0x0000
  41. #define WHITE 0xFFFF
  42.  
  43. char Toggle1Icon = 'z';
  44. int Toggle1 = 0;
  45. int PrevToggle1 = 2;
  46. int yPos = 250;
  47. int Handspeed;
  48.  
  49.  
  50.  
  51. void initDisplay()
  52. {
  53.   ts.begin();
  54.   ts.setRotation(3);
  55.   tft.begin();
  56.   tft.setRotation(3);
  57. }
  58.  
  59.  
  60.  
  61. void DrawToggle1(int PosX, int PosY)
  62. {
  63.     if (Toggle1 != PrevToggle1) {
  64.        // tft.fillRoundRect(PosX, PosY, 80, 80, 15, BUTTONBG);
  65.         tft.drawRoundRect(PosX, PosY, 80, 80, 15, BUTTONEDGE);
  66.         tft.setFont(&icons30pt7b);
  67.         tft.setCursor(PosX + 16, PosY + 55);
  68.         if (Toggle1 == 0) {
  69.             tft.setTextColor(TOGGLEOFF);
  70.             tft.print(Toggle1Icon);
  71.             PrevToggle1 = 0;
  72.         }
  73.         else {
  74.             tft.setTextColor(TOGGLEON);
  75.             tft.print(Toggle1Icon);
  76.             PrevToggle1 = 1;
  77.             int yPos = 250;
  78.         }
  79.     }
  80. }
  81.  
  82.  
  83. void setup() {
  84.   // put your setup code here, to run once:
  85.   initDisplay();
  86.   tft.fillScreen(BLACK);
  87. }
  88.  
  89. void loop() {
  90.  
  91.   DrawToggle1(10,80);
  92. //  DrawFinger();
  93.  
  94.   if (ts.touched()) {
  95.     TS_Point p = ts.getPoint();
  96.     //Vertaal de input van het touchscreen naar coordinaten op het scherm
  97.     p.x = map(p.x, TS_MAXX, TS_MINX, 0, tft.width());
  98.     p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
  99. if ((p.x > 10)&&(p.x<100)&&(p.y>80)&&(p.y<180)){
  100.   if(Toggle1==0){
  101.     Toggle1 = 1;}
  102.     else{
  103.       Toggle1 = 0;}
  104.   DrawToggle1(10,80);
  105.   delay(random(150,3600));
  106.  
  107.   Handspeed = random(4,15);
  108.  
  109.       while (yPos > 100)
  110.     {
  111.       tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
  112.       tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
  113.       yPos -= Handspeed;
  114.     }
  115.     Toggle1 = 0;
  116.   delay(random(350,1800));
  117.       DrawToggle1(10,80);
  118.       tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
  119.   delay(random(250,800));
  120.  
  121.   Handspeed = random(4,15);
  122.  
  123.     while (yPos < 180)
  124.     {
  125.      PrevToggle1=2;
  126.       DrawToggle1(10,80);
  127.       tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
  128.       tft.fillRect(34, yPos-10,20,Handspeed,BLACK);
  129.       tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
  130.       tft.fillRect(54, yPos+64,40,Handspeed,BLACK);
  131.       yPos += Handspeed;
  132.     }
  133.     while (yPos < 250)
  134.     {
  135.       tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
  136.       tft.fillRect(34, yPos-10,20,Handspeed,BLACK);
  137.       tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
  138.       tft.fillRect(54, yPos+64,40,Handspeed,BLACK);
  139.       yPos += Handspeed;
  140.     }
  141.    
  142.   }
  143.  
  144.   }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement