Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_ILI9341.h>
- #include <XPT2046_Touchscreen.h>
- #include "finger.h"
- #include "icons30pt7b.h"
- #define TFT_CS D0
- #define TFT_DC D8
- #define TFT_RST -1
- #define TS_CS D3
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
- XPT2046_Touchscreen ts(TS_CS);
- #define BUTTONBG 0x0000
- #define BUTTONBGACT 0x7BEF
- #define BUTTONEDGE 0x9492
- #define TEXTCOLOR 0xFFFF
- #define SCREENCOLOR 0x0000
- #define TOGGLEON 0x660A
- #define TOGGLEOFF 0x8430
- //Translation of touchscreen coordinates to pixels
- #define TS_MINX 230
- #define TS_MAXX 3600
- #define TS_MINY 330
- #define TS_MAXY 3700
- //Drukbereik touchscreen
- #define MINPRESSURE 400
- #define MAXPRESSURE 3000
- #define BLACK 0x0000
- #define WHITE 0xFFFF
- char Toggle1Icon = 'z';
- int Toggle1 = 0;
- int PrevToggle1 = 2;
- int yPos = 250;
- int Handspeed;
- void initDisplay()
- {
- ts.begin();
- ts.setRotation(3);
- tft.begin();
- tft.setRotation(3);
- }
- void DrawToggle1(int PosX, int PosY)
- {
- if (Toggle1 != PrevToggle1) {
- // tft.fillRoundRect(PosX, PosY, 80, 80, 15, BUTTONBG);
- tft.drawRoundRect(PosX, PosY, 80, 80, 15, BUTTONEDGE);
- tft.setFont(&icons30pt7b);
- tft.setCursor(PosX + 16, PosY + 55);
- if (Toggle1 == 0) {
- tft.setTextColor(TOGGLEOFF);
- tft.print(Toggle1Icon);
- PrevToggle1 = 0;
- }
- else {
- tft.setTextColor(TOGGLEON);
- tft.print(Toggle1Icon);
- PrevToggle1 = 1;
- int yPos = 250;
- }
- }
- }
- void setup() {
- // put your setup code here, to run once:
- initDisplay();
- tft.fillScreen(BLACK);
- }
- void loop() {
- DrawToggle1(10,80);
- // DrawFinger();
- if (ts.touched()) {
- TS_Point p = ts.getPoint();
- //Vertaal de input van het touchscreen naar coordinaten op het scherm
- p.x = map(p.x, TS_MAXX, TS_MINX, 0, tft.width());
- p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
- if ((p.x > 10)&&(p.x<100)&&(p.y>80)&&(p.y<180)){
- if(Toggle1==0){
- Toggle1 = 1;}
- else{
- Toggle1 = 0;}
- DrawToggle1(10,80);
- delay(random(150,3600));
- Handspeed = random(4,15);
- while (yPos > 100)
- {
- tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
- tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
- yPos -= Handspeed;
- }
- Toggle1 = 0;
- delay(random(350,1800));
- DrawToggle1(10,80);
- tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
- delay(random(250,800));
- Handspeed = random(4,15);
- while (yPos < 180)
- {
- PrevToggle1=2;
- DrawToggle1(10,80);
- tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
- tft.fillRect(34, yPos-10,20,Handspeed,BLACK);
- tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
- tft.fillRect(54, yPos+64,40,Handspeed,BLACK);
- yPos += Handspeed;
- }
- while (yPos < 250)
- {
- tft.drawRGBBitmap(32, yPos, Finger, 22, 74);
- tft.fillRect(34, yPos-10,20,Handspeed,BLACK);
- tft.drawRGBBitmap(18, yPos+74, Hand, 100, 49);
- tft.fillRect(54, yPos+64,40,Handspeed,BLACK);
- yPos += Handspeed;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement