Erriez TTP229 touch sensitive 4x4 keypad library for Arduino  1.0.0
This is a TTP229 touch sensitive 4x4 keypad library for Arduino
ErriezTTP229.cpp
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2019-2020 Erriez
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #include <Arduino.h>
26 
27 #include "ErriezTTP229.h"
28 
29 
30 void ErriezTTP229::begin(uint8_t sclPin, uint8_t sdoPin)
31 {
32  _sclPin = sclPin;
33  _sdoPin = sdoPin;
34 
35  pinMode(_sclPin, OUTPUT);
36  pinMode(_sdoPin, INPUT_PULLUP);
37 
38  digitalWrite(_sclPin, HIGH);
39 }
40 
41 uint8_t ErriezTTP229::GetKey16()
42 {
43  uint8_t key = 0;
44 
45  for (uint8_t i = 0; i < 16; i++) {
46  if (GetBit()) {
47  key = i + 1;
48  }
49  }
50  delay(2); // Tout
51 
52  return key;
53 }
54 
55 bool ErriezTTP229::GetBit()
56 {
57  bool retVal;
58 
59  digitalWrite(_sclPin, LOW);
60  delayMicroseconds(2); // 500KHz
61  retVal = !digitalRead(_sdoPin);
62  digitalWrite(_sclPin, HIGH);
63  delayMicroseconds(2); // 500KHz
64 
65  return retVal;
66 }