Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Display program for the google assistant on rpi
- #include <TimedAction.h>
- #include <Adafruit_GFX.h>
- #include <UTFTGLUE.h>
- UTFTGLUE tft(0x0154,A2,A1,A3,A4,A0);
- // Declare which fonts we will be using
- #if !defined(SmallFont)
- extern uint8_t SmallFont[];
- #endif
- String lcdtext;
- //String topString[4];
- //String bottomString[14];
- int h, w, maxscroll; //height width of the screen and maximum scroll of half the screen
- int left = 3; // left offset
- int top = 3; // top offset
- int s = 1; // font size
- int line = s*10; // line height
- String recieved;
- String rec;
- int i = 0;
- int c = 0;
- int A;
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- //TouchScreen_kbv myTouch(XP, YP, XM, YM, 300);
- #include <TouchScreen.h> //Global Library
- #define XP 7
- #define XM A1
- #define YP A2
- #define YM 6
- TouchScreen myTouch(XP, YP, XM, YM, 300);
- TSPoint tp; //Touchscreen_due branch uses Point
- //Touchscreen calibration results just for reminder.
- //PORTRAIT CALIBRATION 240 x 320
- //int x = map(tp.x, 837, 169, 0, 240);
- //int y = map(tp.y, 861, 285, 0, 320);
- //Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
- void readResistiveTouch(void)
- {
- tp = myTouch.getPoint();
- pinMode(YP, OUTPUT); //restore shared pins
- pinMode(XM, OUTPUT);
- }
- bool ISPRESSED()
- {
- int count = 0;
- bool state, oldstate;
- while (count < 2) {
- readResistiveTouch();
- state = tp.z > 20 && tp.z < 1000;
- if (state == oldstate) count++;
- else count = 0;
- oldstate = state;
- //delay(2);
- }
- if (oldstate)
- {
- showpoint();
- }
- }
- void showpoint(void)
- {
- //For now we only need 2 buttons top half of the screen and
- //bottom half.
- if (tp.y < 500)
- {
- Serial.println("Bottom");
- }
- else if (tp.y > 575)
- {
- Serial.println("Top");
- }
- }
- void updateText()
- {
- //Serial.println("height: " + String(height) + " width: " + String(width));
- tft.setColor(YELLOW);
- //buildTopDisplay();
- tft.setColor(WHITE);
- tft.print("http://electronics.henningkarlsen.com", left, top + (h/2));
- }
- TimedAction touchThread = TimedAction(10,ISPRESSED);
- TimedAction textThread = TimedAction(500,updateText);
- void setup()
- {
- Serial.begin(115200);
- //randomSeed(analogRead(5)); //.kbv Due does not like A0
- //pinMode(A0, OUTPUT); //.kbv mcufriend have RD on A0
- //digitalWrite(A0, HIGH);
- // Setup the LCD
- tft.InitLCD();
- tft.setFont(SmallFont);
- tft.setRotation(2);
- tft.clrScr();
- lcdtext = "My lcd display for changing";
- tft.setBackColor(BLACK);
- h = tft.height();
- w = tft.width();
- maxscroll = ((( h/2 ) - top ) / line) - 1;
- tft.setColor(MAGENTA);
- tft.drawRect(w - 1, 0, 1, (h/2) - 1);
- tft.drawRect(w - 1, h/2 , 1, h - 1);
- tft.setColor(WHITE);
- tft.setTextSize(s);
- textThread.check();
- }
- //void buildTopDisplay()
- //{
- // tft.print(lcdtext, left, top + (i*line));
- //}
- void loop()
- {
- touchThread.check();
- //textThread.check();
- if ( Serial.available() > 0 )
- {
- recieved = Serial.readString();
- Serial.println("Received = " + recieved);
- if ( recieved.length() > 2 )
- {
- recieved.trim();
- A = recieved.substring(0,1).toInt();
- recieved = recieved.substring(1,recieved.length());
- c = 0;
- i = 0;
- switch (A)
- {
- case 0:
- //Serial.println("Yes !!! " + recieved.substring(3,recieved.length()));
- while ( c != -1)
- {
- c = recieved.indexOf('|');
- //Serial.println("c = "+ String(c) );
- rec = recieved.substring(0,c);
- //Serial.println(rec);
- recieved = recieved.substring(c+1,recieved.length());
- if (rec.length() > 38)
- {
- rec = rec.substring(0,38);
- }
- else
- {
- for (int j = rec.length();j <= 38;j++)
- {
- rec = rec + " ";
- }
- }
- tft.print(rec, left, top + (i*line));
- i++;
- }
- A = -1;
- Serial.println("TopDone");
- recieved = "";
- rec = "";
- break;
- case 1:
- //Serial.println("Yes !!! " + recieved);
- c = 0;
- i = 0;
- while ( c != -1)
- {
- c = recieved.indexOf('|');
- rec = recieved.substring(0,c);
- recieved = recieved.substring(c+1,recieved.length());
- if (rec.length() > 38)
- {
- rec = rec.substring(0,38);
- }
- else
- {
- for (int j = rec.length();j <= 38;j++)
- {
- rec = rec + " ";
- }
- }
- tft.print(rec, left, top + (h/2) + (i*line));
- i++;
- }
- A = -1;
- Serial.println("BottomDone");
- recieved = "";
- rec = "";
- break;
- default:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement