Skip to content

Commit f08e271

Browse files
committed
Fixed pin settings after completion of pressure(); corrected spelling of pressureThreshold; fix issue adafruit#8 by implementing isTouching
1 parent 2d5821f commit f08e271

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

TouchScreen.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym,
192192
ym_pin = digitalPinToBitMask(_ym);
193193
#endif
194194

195-
pressureThreshhold = 10;
195+
pressureThreshold = 10;
196196
}
197197

198198
int TouchScreen::readTouchX(void) {
@@ -243,6 +243,8 @@ uint16_t TouchScreen::pressure(void) {
243243
int z1 = analogRead(_xm);
244244
int z2 = analogRead(_yp);
245245

246+
uint16_t retval;
247+
246248
if (_rxplate != 0) {
247249
// now read the x
248250
float rtouch;
@@ -253,8 +255,25 @@ uint16_t TouchScreen::pressure(void) {
253255
rtouch *= _rxplate;
254256
rtouch /= 1024;
255257

256-
return rtouch;
258+
retval = rtouch;
257259
} else {
258-
return (1023-(z2-z1));
260+
retval = (1023-(z2-z1));
259261
}
262+
263+
//Clean the touchScreen settings after function is used
264+
//Because LCD may use the same pins
265+
pinMode(_xm, OUTPUT);
266+
digitalWrite(_xm, LOW);
267+
pinMode(_yp, OUTPUT);
268+
digitalWrite(_yp, HIGH);
269+
pinMode(_ym, OUTPUT);
270+
digitalWrite(_ym, LOW);
271+
pinMode(_xp, OUTPUT);
272+
digitalWrite(_xp, HIGH);
273+
274+
return retval;
275+
}
276+
277+
bool TouchScreen::isTouching(void) {
278+
return pressure() > pressureThreshold;
260279
}

TouchScreen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TouchScreen {
4242
int readTouchY();
4343
int readTouchX();
4444
TSPoint getPoint();
45-
int16_t pressureThreshhold;
45+
int16_t pressureThreshold;
4646

4747
private:
4848
uint8_t _yp, _ym, _xm, _xp;

0 commit comments

Comments
 (0)