diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2016-05-17 11:13:23 +1000 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2016-05-17 11:13:23 +1000 |
commit | c91fee0e09eb0386fdd55acdc8080e47a73cee69 (patch) | |
tree | 6f209ccf713c84adf1ca47fda9307f986687c6ff /megalogger/touch.h | |
parent | 09293ac73d85f592fcee7a53670b2749bdf41164 (diff) | |
download | 2021-arduino-obd-c91fee0e09eb0386fdd55acdc8080e47a73cee69.tar.gz 2021-arduino-obd-c91fee0e09eb0386fdd55acdc8080e47a73cee69.tar.bz2 2021-arduino-obd-c91fee0e09eb0386fdd55acdc8080e47a73cee69.zip |
Revised
Diffstat (limited to 'megalogger/touch.h')
-rw-r--r-- | megalogger/touch.h | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/megalogger/touch.h b/megalogger/touch.h deleted file mode 100644 index d0e6d01..0000000 --- a/megalogger/touch.h +++ /dev/null @@ -1,106 +0,0 @@ -#define T_CLK 6 -#define T_CS 5 -#define T_DIN 4 -#define T_DOUT 3 -#define T_IRQ 2 - -#define X_CONST 240 -#define Y_CONST 320 - -#define PREC_TOUCH_CONST 10 - -#define PixSizeX 13.78 -#define PixOffsX 411 - -#define PixSizeY 11.01 -#define PixOffsY 378 - -class CTouch { -public: - void init(void) - { - pinMode(T_CLK, OUTPUT); - pinMode(T_CS, OUTPUT); - pinMode(T_DIN, OUTPUT); - pinMode(T_DOUT, INPUT); - pinMode(T_IRQ, INPUT); - - digitalWrite(T_CS, HIGH); - digitalWrite(T_CLK, HIGH); - digitalWrite(T_DIN, HIGH); - digitalWrite(T_CLK, HIGH); - } - - void writeData(unsigned char data) - { - unsigned char temp; - unsigned char nop; - unsigned char count; - - temp=data; - digitalWrite(T_CLK,LOW); - - for(count=0; count<8; count++) - { - if(temp & 0x80) - digitalWrite(T_DIN, HIGH); - else - digitalWrite(T_DIN, LOW); - temp = temp << 1; - digitalWrite(T_CLK, LOW); - nop++; - digitalWrite(T_CLK, HIGH); - nop++; - } - } - - unsigned int readData() - { - unsigned char nop; - unsigned int data = 0; - unsigned char count; - for(count=0; count<12; count++) - { - data <<= 1; - digitalWrite(T_CLK, HIGH); - nop++; - digitalWrite(T_CLK, LOW); - nop++; - if (digitalRead(T_DOUT)) - data++; - } - return(data); - } - - void read(int& x, int& y) - { - unsigned long tx=0; - unsigned long ty=0; - - digitalWrite(T_CS,LOW); - - for (int i=0; i<PREC_TOUCH_CONST; i++) - { - writeData(0x90); - digitalWrite(T_CLK,HIGH); - digitalWrite(T_CLK,LOW); - ty+=readData(); - - writeData(0xD0); - digitalWrite(T_CLK,HIGH); - digitalWrite(T_CLK,LOW); - tx+=readData(); - } - - digitalWrite(T_CS,HIGH); - x = (tx / PREC_TOUCH_CONST - PixOffsX) / PixSizeX; - y = (ty / PREC_TOUCH_CONST - PixOffsX) / PixSizeX; - } - - bool available() - { - return digitalRead(T_IRQ) == 0; - } -}; - -CTouch touch; |