-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathESP8266_TTP229.ino
73 lines (73 loc) · 2.33 KB
/
ESP8266_TTP229.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*---------------------------------------------------------------------
ESP8266 - TTP229 - With INT Using GPIO9 and GPIO10
Programa: Netto Scaff for Kameda Corp. | Curitiba - Brazil
/---------------------------------------------------------------------*/
int SCLPin = 10; //GPIO10 - INPUT or OUTPUT
int SDOPin = 9; //GPIO9 - INPUT ONLY | OUTPUT -> WDG
int Key=0; // Key 1 to 16 (No Key=0 is optional)
boolean Touch=0;//1=On 0=Off
boolean In;
unsigned int DTA=0;
unsigned int DTB=0;
//---------------------------------------------------------------------
// **** INT 16 KEY READ ***
//---------------------------------------------------------------------
void Int_Key(){
digitalWrite(SCLPin,HIGH);
detachInterrupt(digitalPinToInterrupt(SDOPin));//Stop Int
Serial.println();
Serial.println("Int Pino L->H");
DTA = 0;
Key=0;
delayMicroseconds(93);
digitalWrite(SDOPin, LOW);
delayMicroseconds(10);
pinMode(SDOPin , INPUT);
//------------------------
for (int i = 0; i < 17; i++)//Read 17 Bits for Safe
{ digitalWrite(SCLPin, HIGH);
delayMicroseconds(1);
digitalWrite(SCLPin, LOW);
delayMicroseconds(1);
In=digitalRead(SDOPin);
if(Key==0 && In==0){Key=i+1;}
DTA |= In << i;
}
digitalWrite(SCLPin,HIGH);
delayMicroseconds(2);
//------------------------
if(DTB!=DTA && DTA!=131071){
DTB=DTA;
//Serial.println(DTA,BIN);
//Serial.println(DTA,HEX);
//Serial.println(DTA,DEC);
Serial.println(Key);
Serial.println("Touch 1");
Touch=1;
}else{
//Key=0;// Optional
Serial.println("Touch 0");
DTB=0;
Touch=0;}
attachInterrupt(digitalPinToInterrupt(SDOPin), Int_Key, RISING);//Restart Int for new Key
}
//---------------------------------------------------------------------
// **** SETUP ***
//---------------------------------------------------------------------
void setup() {
Serial.begin(115200);
pinMode(SDOPin,INPUT_PULLUP);
pinMode(SCLPin,OUTPUT);//
digitalWrite(SDOPin,HIGH);
digitalWrite(SCLPin,HIGH);
attachInterrupt(digitalPinToInterrupt(SDOPin), Int_Key, RISING);
Serial.println();
Serial.println("Start Key 16");
}
//---------------------------------------------------------------------
// **** LOOP ***
//---------------------------------------------------------------------
void loop() {
yield();
ESP.wdtFeed();
}