Double_G

Konica Minolta MFP Touch Panel reuse

Jan 18th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. #include <Wire.h>               //Connect Konica Minolta touch screen SDA to A04 and SCK to A05
  2. #include <Adafruit_GFX.h>       //Core graphics library
  3. #include <Adafruit_ST7735.h>    //Hardware-specific library
  4. #include <SPI.h>
  5.  
  6. #define TFT_SCLK 13
  7. #define TFT_MOSI 11
  8. #define TFT_CS 10
  9. #define TFT_RST 9
  10. #define TFT_DC 8
  11.  
  12. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
  13.  
  14. byte register1;
  15. byte register2;
  16. byte register3;
  17. byte register4;
  18. byte register5;
  19. byte register6;
  20. byte register7;
  21. byte register8;
  22. byte register9;
  23. byte register10;
  24. byte register11;
  25.  
  26. int xx1, xx2, yy1, yy2, r, x, y; //variables
  27.  
  28. void setup() {
  29.   tft.initR(INITR_REDTAB);    //initialize a ST7735S chip, black tab
  30.   tft.fillScreen(ST7735_BLACK); //clear screen
  31.   Wire.begin(0x5c);           //join i2c bus (address optional for master)
  32.   //Serial.begin(115200);     //start serial for output
  33.   //Serial.println("starting"); //print "starting" to serial
  34. }
  35.  
  36. void loop() {
  37.   Wire.beginTransmission(0x5C); //touch panel address
  38.   Wire.write(0x00);       //start register
  39.   Wire.endTransmission();     //communication close
  40.   Wire.requestFrom(0x5c, 11);   //how many byte to read from address 0x5C
  41.  
  42.   register1 = Wire.read();    //first byte reading (Touch counter)
  43.   register2 = Wire.read();    //second reading (????)
  44.   register3 = Wire.read();    //etc etc etc (first finger X coordinate low byte)
  45.   register4 = Wire.read();    //first finger X coordinate high byte
  46.   register5 = Wire.read();    //first finger Y coordinate low byte
  47.   register6 = Wire.read();    //first finger Y coordinate high byte
  48.   register7 = Wire.read();    //??
  49.   register8 = Wire.read();    //second finger X coordinate low byte
  50.   register9 = Wire.read();    //second finger X coordinate high byte
  51.   register10 = Wire.read();   //second finger Y coordinate low byte
  52.   register11 = Wire.read();   //second finger Y coordinate high byte
  53.  
  54.  
  55.   xx1 = (register4 * 256) + register3;    //calculate 2 byte to touch coordinate (0-1024)
  56.   yy1 = (register6 * 256) + register5;    //calculate 2 byte to touch coordinate (0-600)
  57.   xx2 = (register9 * 256) + register8;    //calculate 2 byte to touch coordinate (0-1024)
  58.   yy2 = (register11 * 256) + register10;  //calculate 2 byte to touch coordinate (0-600)
  59.  
  60.   xx1 = xx1 / 8;              //divide by 8 to scale 128x128
  61.   xx1 = 128 - xx1;
  62.  
  63.   yy1 = yy1 / 4.6875;         //divide by 4.6 to scale 128x128
  64.   yy1 = 128 - yy1;
  65.  
  66.   xx2 = xx2 / 8;
  67.   xx2 = 128 - xx2;
  68.  
  69.   yy2 = yy2 / 4, 6875;
  70.   yy2 = 128 - yy2;
  71.  
  72.   //x= xx1 - xx2;             //calculate radius
  73.   //y= yy2 - yy2;
  74.  
  75.   //x= x*x;                   //pythagoras
  76.   //y= y*y;
  77.   //r = x +y;
  78.   //r= sqrt(r);
  79.  
  80.   //Serial.print("Touch counter:");
  81.   //Serial.println(register1);
  82.   //Serial.print("First finger horinzontal (X) coordinate:");
  83.   //Serial.println(xx1);
  84.  
  85.   //Serial.print("First finger vertical (Y) coordinate:");
  86.   //Serial.println(yy1);
  87.  
  88.   //Serial.print("Second finger horinzontal (X) coordinate:");
  89.   //Serial.println(xx2);
  90.  
  91.   //Serial.print("Second finger vertical (Y) coordinate:");
  92.   //Serial.println(yy2);
  93.  
  94.   tft.drawPixel(xx1, yy1, ST7735_WHITE);  //write dots to screen first finger
  95.  
  96.   tft.drawPixel(xx2, yy2, ST7735_GREEN);  //write dots to screen second finger
  97.  
  98.   //tft.drawLine(xx1,yy1,xx2,yy2, ST7735_WHITE); // test
  99.  
  100.  
  101.   //if (register1 <= 1) {             //test
  102.   //  tft.drawPixel(xx1, yy1, ST7735_WHITE);    //test
  103.   //}                       //test
  104.   //else {tft.drawCircle (xx1,yy1,r,ST7735_BLUE); //test
  105.   //}                       //test
  106.   //delay(100);                   //test
  107. }
Advertisement
Add Comment
Please, Sign In to add comment